Skip to content

Instantly share code, notes, and snippets.

@dmennis
Last active March 19, 2019 18:39
Show Gist options
  • Save dmennis/8fba1d9dc738141452ceeb9f98992f40 to your computer and use it in GitHub Desktop.
Save dmennis/8fba1d9dc738141452ceeb9f98992f40 to your computer and use it in GitHub Desktop.
AWS SDK for iOS 2.7.0+
import UIKit
import AWSMobileClient
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
initializeAWSMobileClient() // Initialize the AWSMobileClient
}
// Initializing the AWSMobileClient and take action based on current user state
func initializeAWSMobileClient() {
AWSMobileClient.sharedInstance().initialize { (userState, error) in
//self.addUserStateListener() // Register for user state changes
if let userState = userState {
switch(userState){
case .signedIn: // is Signed IN
print("Logged In")
print("Cognito Identity Id (authenticated): \(AWSMobileClient.sharedInstance().identityId))")
case .signedOut: // is Signed OUT
print("Logged Out")
DispatchQueue.main.async {
self.showSignIn()
}
case .signedOutUserPoolsTokenInvalid: // User Pools refresh token INVALID
print("User Pools refresh token is invalid or expired.")
DispatchQueue.main.async {
self.showSignIn()
}
case .signedOutFederatedTokensInvalid: // Facebook or Google refresh token INVALID
print("Federated refresh token is invalid or expired.")
DispatchQueue.main.async {
self.showSignIn()
}
default:
AWSMobileClient.sharedInstance().signOut()
}
} else if let error = error {
print(error.localizedDescription)
}
}
}
//...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment