我正在尝试从我自己的 iOS 访问 Instagram 应用程序以进行 OAuth 注册。我有以下代码,它正在通过 Safari 访问 Instagram,但我希望该应用程序在手机上打开。也在寻找一种从 Instagram 为我的应用程序获取身份验证 token 的方法。
这是我的代码:
func startOAuth2Login()
{
....
let authPath:String = "https://api.instagram.com/oauth/authorize/?client_id=\(clientID)&redirect_uri=grokInstagram://?aParam=paramVal&response_type=code"
var instagramHooks = "instagram://app"
var instagramUrl = NSURL(string: instagramHooks)
if UIApplication.sharedApplication().canOpenURL(instagramUrl!)
{
UIApplication.sharedApplication().openURL(instagramUrl!)
} else {
//redirect to safari because the user doesn't have Instagram
print("didn't have it")
UIApplication.sharedApplication().openURL(NSURL(string: authPath)!)
}
....
最佳答案
iOS 9 对 URL 方案的处理做了一个小改动。您必须使用 Info.plist
中的 LSApplicationQueriesSchemes
键将您的应用调出的网址列入白名单。
更多信息:http://useyourloaf.com/blog/querying-url-schemes-with-canopenurl.html
关于ios - 带有 Instagram 的 Swift 2 OAuth 无法打开 Instagram 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32878491/