【问题标题】:AWS iOS Swift 3 Cognito Type does not conform to protocolAWS iOS Swift 3 Cognito Type 不符合协议
【发布时间】:2017-01-04 12:38:37
【问题描述】:

您好,我在 iOS 中使用 AWS Mobile hub,我遵循了 aut with cognito 的介绍。它说我必须从示例中导入用户池文件。我这样做了,但这会给我一个错误:

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()
            })
        }
    }
}

错误:

类型“SignInViewController”不符合协议 'AWSCognitoIdentityPasswordAuthentication'

还有:

协议需要函数 'getDetails(_:passwordAuthenticationCompletionSource:)' 类型 '(AWSCognitoIdentityPasswordAuthenticationInput, AWSTaskCompletionSource) -> 无效';你想添加一个存根吗? (AWSCognitoIdentityProvider.AWSCognitoIdentityPasswordAuthentication)

和:

候选人的类型不匹配 '(AWSCognitoIdentityPasswordAuthenticationInput, AWSTaskCompletionSource) -> ()'

【问题讨论】:

    标签: ios amazon-web-services swift3 aws-mobilehub


    【解决方案1】:

    根据docs,任何符合AWSCognitoIdentityPasswordAuthentication的类都应该实现:

    – getPasswordAuthenticationDetails:passwordAuthenticationCompletionSource
    – didCompletePasswordAuthenticationStepWithError
    

    您没有实现它们,因此出现错误。

    编辑 是的,你是对的,Swift 3 中的函数签名发生了变化(参见here)。

    他们应该是这样的:

    func getDetails(_ authenticationInput: AWSCognitoIdentityPasswordAuthenticationInput, passwordAuthenticationCompletionSource: AWSTaskCompletionSource<AWSCognitoIdentityPasswordAuthenticationDetails>)
    func didCompleteStepWithError(_ error: Error?)
    

    看起来您的第一个 func 版本略有不同。

    【讨论】:

    • 它们已经实现,只是在 Swift 3 中重命名
    猜你喜欢
    • 1970-01-01
    • 2017-03-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-28
    • 2017-06-05
    • 1970-01-01
    相关资源
    最近更新 更多