【发布时间】:2017-01-31 07:35:05
【问题描述】:
我正在将我的项目从 Swift 2.3 迁移到 Swift 3。并且遇到了预期的困难。
这是一个用于 OAuth 的函数,使用 OAuthSwift。我试图转换
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)
}
}
但我在
处遇到错误oauthswift.authorize(withCallbackURL: URL(string: info.callBackUrl)!, scope: info.scope, state: info.state, success: { (credential, response, parameters) in
错误状态
对成员'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)
}
)
更新:
在我键入成功和失败处理程序之前不会出现错误。这很好:
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
}
所以请指导我谢谢。
【问题讨论】:
标签: ios oauth-2.0 swift2 swift3