AWS iOS Swift 3 Cognito 类型不符合协议
AWS iOS Swift 3 Cognito Type does not conform to protocol
您好,我在 iOS 中使用 AWS Mobile hub,我遵循了使用 cognito 进行 aut 的介绍。它说我必须从示例中导入用户池文件。我这样做了,但这会引发错误:
extension SignInViewController: AWSCognitoIdentityPasswordAuthentication {
func getDetails(_ authenticationInput: AWSCognitoIdentityPasswordAuthenticationInput, passwordAuthenticationCompletionSource: AWSTaskCompletionSource<AnyObject>) {
self.passwordAuthenticationCompletion = passwordAuthenticationCompletionSource
}
func didCompleteStepWithError(_ error: Error?) {
if let error = error {
DispatchQueue.main.async(execute: {
UIAlertView(title: "ERROR",
message: error.localizedDescription,
delegate: nil,
cancelButtonTitle: "Ok").show()
})
}
}
}
错误:
Type 'SignInViewController' does not conform to protocol
'AWSCognitoIdentityPasswordAuthentication'
还有:
Protocol requires function
'getDetails(_:passwordAuthenticationCompletionSource:)' with type
'(AWSCognitoIdentityPasswordAuthenticationInput,
AWSTaskCompletionSource)
-> Void'; do you want to add a stub? (AWSCognitoIdentityProvider.AWSCognitoIdentityPasswordAuthentication)
和:
Candidate has non-matching type
'(AWSCognitoIdentityPasswordAuthenticationInput,
AWSTaskCompletionSource) -> ()'
根据 docs,任何符合 AWSCognitoIdentityPasswordAuthentication
的 class 应该实现:
– getPasswordAuthenticationDetails:passwordAuthenticationCompletionSource
– didCompletePasswordAuthenticationStepWithError
您没有实施它们,因此出现错误。
编辑
是的,你是对的,函数签名在 Swift 3 中发生了变化(参见 here)。
他们应该是这样的:
func getDetails(_ authenticationInput: AWSCognitoIdentityPasswordAuthenticationInput, passwordAuthenticationCompletionSource: AWSTaskCompletionSource<AWSCognitoIdentityPasswordAuthenticationDetails>)
func didCompleteStepWithError(_ error: Error?)
看起来您的第一个函数版本略有不同。
您好,我在 iOS 中使用 AWS Mobile hub,我遵循了使用 cognito 进行 aut 的介绍。它说我必须从示例中导入用户池文件。我这样做了,但这会引发错误:
extension SignInViewController: AWSCognitoIdentityPasswordAuthentication {
func getDetails(_ authenticationInput: AWSCognitoIdentityPasswordAuthenticationInput, passwordAuthenticationCompletionSource: AWSTaskCompletionSource<AnyObject>) {
self.passwordAuthenticationCompletion = passwordAuthenticationCompletionSource
}
func didCompleteStepWithError(_ error: Error?) {
if let error = error {
DispatchQueue.main.async(execute: {
UIAlertView(title: "ERROR",
message: error.localizedDescription,
delegate: nil,
cancelButtonTitle: "Ok").show()
})
}
}
}
错误:
Type 'SignInViewController' does not conform to protocol 'AWSCognitoIdentityPasswordAuthentication'
还有:
Protocol requires function 'getDetails(_:passwordAuthenticationCompletionSource:)' with type '(AWSCognitoIdentityPasswordAuthenticationInput, AWSTaskCompletionSource) -> Void'; do you want to add a stub? (AWSCognitoIdentityProvider.AWSCognitoIdentityPasswordAuthentication)
和:
Candidate has non-matching type '(AWSCognitoIdentityPasswordAuthenticationInput, AWSTaskCompletionSource) -> ()'
根据 docs,任何符合 AWSCognitoIdentityPasswordAuthentication
的 class 应该实现:
– getPasswordAuthenticationDetails:passwordAuthenticationCompletionSource
– didCompletePasswordAuthenticationStepWithError
您没有实施它们,因此出现错误。
编辑 是的,你是对的,函数签名在 Swift 3 中发生了变化(参见 here)。
他们应该是这样的:
func getDetails(_ authenticationInput: AWSCognitoIdentityPasswordAuthenticationInput, passwordAuthenticationCompletionSource: AWSTaskCompletionSource<AWSCognitoIdentityPasswordAuthenticationDetails>)
func didCompleteStepWithError(_ error: Error?)
看起来您的第一个函数版本略有不同。