【发布时间】:2015-09-30 22:33:41
【问题描述】:
我正在尝试为我正在开发的应用获取 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
}
}
这是触发 safari 打开的我的 API Manager 代码:
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)
}
}
....
}
任何帮助将不胜感激!
【问题讨论】:
-
您知道
handleOpenURL:已被弃用,对吧?在 iOS 9 中,您应该使用func application(_ app: UIApplication, openURL url: NSURL, options options: [String : AnyObject]) -> Bool -
我不知道,谢谢!
-
效果很好,非常感谢!
-
那么我会给出答案。很高兴它成功了!
-
知道如果安装在设备上,我将如何从 Instagram 应用获取 OAuth2 令牌?哦,还有,你写了两次“选项”,_抛出了一个错误,但 Xcode 修复了它。
标签: ios swift2 instagram-api