Last active
March 19, 2019 18:39
-
-
Save dmennis/8fba1d9dc738141452ceeb9f98992f40 to your computer and use it in GitHub Desktop.
AWS SDK for iOS 2.7.0+
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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