gpt4 book ai didi

ios - handleOpenURL 不会触发 iOS Swift 2

转载 作者:塔克拉玛干 更新时间:2023-11-01 21:21:16 25 4
gpt4 key购买 nike

我正在尝试为我正在开发的应用程序获取 Instagram 身份验证 token ,我打开了 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
}

}

这是触发 safari 打开的我的 API 管理器代码:

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 {

关于ios - handleOpenURL 不会触发 iOS Swift 2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32876631/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com