By White Bear


2019-12-02 22:58:28 8 Comments

AWSMobileClient.default().federatedSignIn(providerName: IdentityProvider.facebook.rawValue, token: (result?.token!.tokenString)!, completionHandler: { (userState, error) in
if let error = error{
    print("Initialize Error: ", error.localizedDescription)
}else{
    print("User State: ", userState!)//User State:  signedIn
    switch (userState) {
    case .signedIn?:
        DispatchQueue.main.async {
            self.getAWSToken()
        }
    default:
        print("Sign In needs info which is not et supported.")
    }
}
})  
func getAWSToken(){
    AWSMobileClient.default().getTokens { (result, error) in
        if error == nil{
            print("JWT Token: ", (result?.idToken?.tokenString!)!)
            print("Expire : ", (result?.expiration!)!)
            AppData.sharedInstance.JWT_Token = (result?.idToken?.tokenString!)! as String
            AppData.sharedInstance.Refresh_Token = (result?.refreshToken?.tokenString!)! as String
            let dateFormatter = DateFormatter()
            dateFormatter.dateFormat = "yyyy-MM-dd H:mm:ss"
            let dtStr = dateFormatter.string(from: (result?.expiration!)!)
            let expireDate =  Utility.UTCToLocal(date: dtStr)
            AppData.sharedInstance.JWT_Token_Expire_Date = expireDate
            UserDefaults.standard.set(AppData.sharedInstance.JWT_Token_Expire_Date, forKey: Utility.KEY_JWT_TOKEN_EXPIRE_DATE)
            UserDefaults.standard.set(AppData.sharedInstance.JWT_Token, forKey: Utility.KEY_JWT_Token)
            UserDefaults.standard.set(AppData.sharedInstance.Refresh_Token, forKey: Utility.KEY_Refresh_Token)
            DispatchQueue.main.async {
                self.getUserInfo()
                RSApiManager.shared.postDeviceToken(dToken: Utility.MY_TOKEN)
            }
        }else{
            print("Error: ", error.debugDescription)
        }
    }
}

AWSMobileClient.default().getTokens always shows

"Error: Optional(AWSMobileClient.AWSMobileClientError.notSignedIn(message: "User is not signed in, please sign in to use this API."))"

even it shows success "User State: signedIn" for federateSignIn.

AWSMobileClient.default().signIn(username: username, password: password) { (signInResult, error) in
self.getAWSToken() 
}

It is working fine after signIn() but not for federateSignIn().

0 comments

Related Questions

Sponsored Content

17 Answered Questions

[SOLVED] How do I call Objective-C code from Swift?

  • 2014-06-02 20:05:42
  • David Mulder
  • 275220 View
  • 940 Score
  • 17 Answer
  • Tags:   objective-c swift

23 Answered Questions

[SOLVED] @selector() in Swift?

20 Answered Questions

[SOLVED] #pragma mark in Swift?

  • 2014-06-03 14:05:56
  • Arbitur
  • 214702 View
  • 915 Score
  • 20 Answer
  • Tags:   swift

1 Answered Questions

Cannot refresh session of cognito

33 Answered Questions

[SOLVED] Split a String into an array in Swift?

15 Answered Questions

[SOLVED] Swift for loop: for index, element in array?

  • 2014-06-04 03:19:21
  • thinker3
  • 407865 View
  • 740 Score
  • 15 Answer
  • Tags:   arrays swift

23 Answered Questions

[SOLVED] dispatch_after - GCD in Swift?

19 Answered Questions

[SOLVED] Do Swift-based applications work on OS X 10.9/iOS 7 and lower?

  • 2014-06-02 19:25:57
  • MeIr
  • 109233 View
  • 613 Score
  • 19 Answer
  • Tags:   ios macos swift

16 Answered Questions

[SOLVED] #ifdef replacement in the Swift language

9 Answered Questions

[SOLVED] Swift Beta performance: sorting arrays

Sponsored Content