handleOpenURL 不会触发 iOS Swift 2
handleOpenURL won't trigger iOS Swift 2
我正在尝试为我正在开发的应用程序获取 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)
}
}
....
}
如有任何帮助,我们将不胜感激!
在 iOS 9 中,application:handleOpenURL:
已弃用。相反,您应该使用:
func application(app: UIApplication,
openURL url: NSURL, options: [String : AnyObject]) -> Bool {
正确的语法似乎是
func application(_ app: UIApplication,
open url: URL,
options: [UIApplicationOpenURLOptionsKey : Any]) -> Bool {
return true
}
根据https://developer.apple.com/reference/uikit/uiapplicationdelegate/1623112-application
我正在尝试为我正在开发的应用程序获取 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)
}
}
....
}
如有任何帮助,我们将不胜感激!
在 iOS 9 中,application:handleOpenURL:
已弃用。相反,您应该使用:
func application(app: UIApplication,
openURL url: NSURL, options: [String : AnyObject]) -> Bool {
正确的语法似乎是
func application(_ app: UIApplication,
open url: URL,
options: [UIApplicationOpenURLOptionsKey : Any]) -> Bool {
return true
}
根据https://developer.apple.com/reference/uikit/uiapplicationdelegate/1623112-application