【发布时间】:2019-04-21 19:04:10
【问题描述】:
我正在快速开发一个应用程序,我使用 AWS 移动服务进行身份验证,并使用 AWS Lambda 进行一些后端处理。我一切正常,有一天(离开应用程序一个月左右后),它开始抛出这个错误:
GetId failed. Error is [Error Domain=com.amazonaws.AWSCognitoIdentityProviderErrorDomain Code=-1000 "Authentication delegate not set" UserInfo {NSLocalizedDescription=Authentication delegate not set}]
Unable to refresh. Error is [Error Domain=com.amazonaws.AWSCognitoIdentityProviderErrorDomain Code=-1000 "Authentication delegate not set"
这让我很生气,因为它已经在工作了。会发生什么变化?
在 appDelegate 中,我有:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey : Any]? = nil) -> Bool {
// Uncomment to turn on logging, look for "Welcome to AWS!" to confirm success
AWSDDLog.add(AWSDDTTYLogger.sharedInstance)
AWSDDLog.sharedInstance.logLevel = .error
// Instantiate AWSMobileClient to get AWS user credentials
return AWSMobileClient.sharedInstance().interceptApplication(application, didFinishLaunchingWithOptions:launchOptions)
}
在我进行任何调用之前它实际上会抛出错误,所以我认为上面的行可能会触发问题?
要登录,我在主视图控制器中执行以下操作:
override func viewDidLoad() {
super.viewDidLoad()
if !AWSSignInManager.sharedInstance().isLoggedIn {
presentAuthUIViewController()
}
else{
getCredentials()
}
...
}
func presentAuthUIViewController() {
let config = AWSAuthUIConfiguration()
config.enableUserPoolsUI = true
config.backgroundColor = UIColor.white
config.logoImage = #imageLiteral(resourceName: "logoQ")
config.isBackgroundColorFullScreen = true
config.canCancel = true
AWSAuthUIViewController.presentViewController(
with: self.navigationController!,
configuration: config, completionHandler: { (provider:
AWSSignInProvider, error: Error?) in
if error == nil {
self.getCredentials()
} else {
// end user faced error while loggin in, take any required action here.
}
})
}
func getCredentials() {
let serviceConfiguration = AWSServiceConfiguration(region: .USEast1, credentialsProvider: nil)
let userPoolConfiguration = AWSCognitoIdentityUserPoolConfiguration(clientId: "id",
clientSecret: "secret",
poolId: "id")
AWSCognitoIdentityUserPool.register(with: serviceConfiguration, userPoolConfiguration: userPoolConfiguration, forKey: "key")
let pool = AWSCognitoIdentityUserPool(forKey: "key")
if let username = pool.currentUser()?.username {
userName = username
}
它登录,我检索用户名。
有什么建议吗?我按照其他帖子中的一些说明进行操作,但它们不起作用,而且最让我感到不安的是它起作用了!
提前致谢
【问题讨论】:
-
我尝试在 appDelegate 中添加 pool.delegate = self 和相应的扩展,但还是不行
标签: swift amazon-web-services amazon-cognito aws-mobilehub