ios - 带有 Instagram 的 Swift 2 OAuth 无法打开 Instagram 应用程序

标签 ios oauth swift2 instagram-api

我正在尝试从我自己的 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 键将您的应用调出的网址列入白名单。

enter image description here

更多信息:http://useyourloaf.com/blog/querying-url-schemes-with-canopenurl.html

关于ios - 带有 Instagram 的 Swift 2 OAuth 无法打开 Instagram 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32878491/

相关文章:

xcode - 如何在 Xcode 7 项目中包含 ReactiveCocoa 3.0

objective-c - 如何从 obj-c/ios 中的堆栈跟踪获取源代码行

ios - Swift 3 中的不安全指针

objective-c - App 日历功能不再适用于 ios 6

android - 如何从 Android 访问 Bearer 认证服务

python - 获取易趣 OAuth token

ios - CollectionView 滚动时更改单元格背景图像

ios - Swift - 如何在文本字段外点击后关闭数字键盘

android - Gmail 登录时获取无效的 Authtoken?

swift - 为什么 Swift 在这里给我一个 EXC_BAD_INSTRUCTION?