我正在尝试为我正在使用的应用程序获取Instagram身份验证令牌,我有应用程序打开safari,我能够登录然后它将我发送回应用程序,但是当它将我转移回应用程序时,handleOpenURL没有在AppDelegate中触发。以下是我的代码示例:
import UIKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
....
func application(application: UIApplication, handleOpenURL url: NSURL) -> Bool {
InstagramAPIManager.sharedInstance.processOAuthStep1Response(url)
print(url)
print("handleOpenURL")
return true
}
}
这是我的API管理器代码触发safari打开:
import Foundation
import Alamofire
class InstagramAPIManager {
static let sharedInstance = InstagramAPIManager()
func startOAuth2Login() {
let clientID: String = "abcdefg"
let authPath:String = "https://api.instagram.com/oauth/authorize/?client_id=\(clientID)&redirect_uri=grokInstagram://?aParam=paramVal&response_type=code"
if let authURL:NSURL = NSURL(string: authPath)
{
UIApplication.sharedApplication().openURL(authURL)
}
}
....
}
任何帮助将不胜感激!
答案 0 :(得分:5)
In iOS 9, application:handleOpenURL:
is deprecated. Instead, you should be using:
func application(app: UIApplication,
openURL url: NSURL, options: [String : AnyObject]) -> Bool {
答案 1 :(得分:0)
正确的语法似乎是
func application(_ app: UIApplication,
open url: URL,
options: [UIApplicationOpenURLOptionsKey : Any]) -> Bool {
return true
}
根据https://developer.apple.com/reference/uikit/uiapplicationdelegate/1623112-application