使用Instagram的Swift 2 OAuth无法打开Instagram应用程序

时间:2015-10-01 02:23:48

标签: ios oauth swift2 instagram-api

我试图从我自己的iOS访问Instagram应用程序进行OAuth注册。我有以下代码,它正在通过Safari访问Instagram,但我希望该应用程序打开,如果它在手机上。还在寻找一种从Instagram获取身份验证令牌的方法。

这是我的代码:

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)!)
    }
....

1 个答案:

答案 0 :(得分:1)

iOS 9对URL方案的处理做了一些小改动。您必须使用LSApplicationQueriesSchemes中的Info.plist密钥将您的应用发出的网址列入白名单。

enter image description here

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