Uma*_*zal 10 ios oauth-2.0 swift2 swift3
我正在将我的项目从Swift 2.3迁移到Swift 3.并且遇到了预期的困难.
这是一个使用OAuthSwift用于OAuth的函数.我试过转换
class func OAuthSwiftAuthorization(inViewController viewController: UIViewController, withOAuthInfo info:FitnessTracker, successHandler:@escaping MyOAuthNewSuccessHandler, failure: @escaping ((_ error: NSError) -> Void)) {
let oauthswift = OAuth2Swift(
consumerKey: info.consumerKey,
consumerSecret: info.consumerSecret,
authorizeUrl: info.authorizeUrl,
accessTokenUrl: info.accessTokenUrl,
responseType: info.responseType
)
oauthswift.authorizeURLHandler = SafariURLHandler(viewController: viewController, oauthSwift: oauthswift)
oauthswift.accessTokenBasicAuthentification = true
oauthswift.allowMissingStateCheck = true
oauthswift.authorize(withCallbackURL: URL(string: info.callBackUrl)!, scope: info.scope, state: info.state, success: { (credential, response, parameters) in
successHandler(credential, response, parameters)
}) { (error) in
failure(error: error)
print(error.localizedDescription)
}
}
Run Code Online (Sandbox Code Playgroud)
但是我收到了错误
oauthswift.authorize(withCallbackURL: URL(string: info.callBackUrl)!, scope: info.scope, state: info.state, success: { (credential, response, parameters) in
Run Code Online (Sandbox Code Playgroud)
错误状态
对成员'authorize的不明确引用(withCallbackURL:scope:state:parameters:headers:success:failure :)'
这是Swift 2的工作代码.
oauthswift.authorizeWithCallbackURL(
URL(string: info.callBackUrl)!,
scope: info.scope, state:info.state,
success: { credential, response, parameters in
successHandler(credientials: credential, response: response, params: parameters)
},
failure: { error in
failure(error: error)
print(error.localizedDescription)
}
)
Run Code Online (Sandbox Code Playgroud)
更新:
错误没有出现unitil我输入成功和faliure handelrs.这符合罚款:
oauthswift.authorize(withCallbackURL: URL(string: info.callBackUrl)!, scope: info.scope, state: info.state, success: { (credential, response, parameters) in
// successHandler(credential, response, parameters)
}) { (erorr) in
// failure(error: error
}
Run Code Online (Sandbox Code Playgroud)
所以请指导我谢谢.
And*_*jen 12
我认为这个问题是由Swift的类型推断和闭包的一些缺点引起的.您可以尝试以下方法之一:
要么不使用尾随闭包,例如
oauthswift.authorize(withCallbackURL: URL(string: info.callBackUrl)!, scope: info.scope, state: info.state, success: { (credential, response, parameters) in
successHandler(credential, response, parameters)
}, failure: { (error) in
failure(error: error)
print(error.localizedDescription)
})
Run Code Online (Sandbox Code Playgroud)
或提供错误的显式类型,例如
oauthswift.authorize(withCallbackURL: URL(string: info.callBackUrl)!, scope: info.scope, state: info.state, success: { (credential, response, parameters) in
successHandler(credential, response, parameters)
}) { (error: Error) in
failure(error: error)
print(error.localizedDescription)
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
31021 次 |
| 最近记录: |