0
我使用swifter搶訪問令牌回調IOS不返回認證
swifter.authorize(with: URL(string: "callback://")!, presentFrom: self, success: { accessToken, response in
print("HELLO")
print(accessToken)
// ...
}, failure: { error in
// ...
})
我可以成功登錄,因爲應用程序打開了SFSafariViewController,但當時我沒有直接回我的應用程序,成功回調是永遠不會被調用
這裏是爲更快的代碼,我看到presentFrom被假設是SFSafariViewController,但沒有被觸發
public func authorize(with callbackURL: URL, presentFrom presentingViewController: UIViewController? , success: TokenSuccessHandler?, failure: FailureHandler? = nil) {
self.postOAuthRequestToken(with: callbackURL, success: { token, response in
var requestToken = token!
NotificationCenter.default.addObserver(forName: .SwifterCallbackNotification, object: nil, queue: .main) { notification in
NotificationCenter.default.removeObserver(self)
presentingViewController?.presentedViewController?.dismiss(animated: true, completion: nil)
let url = notification.userInfo![CallbackNotification.optionsURLKey] as! URL
let parameters = url.query!.queryStringParameters
requestToken.verifier = parameters["oauth_verifier"]
self.postOAuthAccessToken(with: requestToken, success: { accessToken, response in
self.client.credential = Credential(accessToken: accessToken!)
success?(accessToken!, response)
}, failure: failure)
}
let authorizeURL = URL(string: "oauth/authorize", relativeTo: TwitterURL.oauth.url)
let queryURL = URL(string: authorizeURL!.absoluteString + "?oauth_token=\(token!.key)")!
if #available(iOS 9.0, *) , let delegate = presentingViewController as? SFSafariViewControllerDelegate {
let safariView = SFSafariViewController(url: queryURL)
safariView.delegate = delegate
presentingViewController?.present(safariView, animated: true, completion: nil)
} else {
UIApplication.shared.openURL(queryURL)
}
}, failure: failure)
}
爲SFSafariViewController的delgate方法
你艾威找到解決這個?我現在也在爲此付出努力 –