Swift 2 使用 Instagram 的 OAuth 无法打开 Instagram 应用
Swift 2 OAuth with Instagram can't open the Instagram app
我正在尝试从我自己的 iOS 访问 Instagram 应用程序以进行 OAuth 注册。我有以下代码,它可以通过 Safari 访问 Instagram,但我希望该应用程序在 phone 上打开。也在寻找一种从 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)!)
}
....
iOS 9 对URL方案的处理做了一个小改动。您必须将 url 列入白名单,您的应用将使用 Info.plist
.
中的 LSApplicationQueriesSchemes
键调出该 url
更多信息:http://useyourloaf.com/blog/querying-url-schemes-with-canopenurl.html
我正在尝试从我自己的 iOS 访问 Instagram 应用程序以进行 OAuth 注册。我有以下代码,它可以通过 Safari 访问 Instagram,但我希望该应用程序在 phone 上打开。也在寻找一种从 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)!)
}
....
iOS 9 对URL方案的处理做了一个小改动。您必须将 url 列入白名单,您的应用将使用 Info.plist
.
LSApplicationQueriesSchemes
键调出该 url
更多信息:http://useyourloaf.com/blog/querying-url-schemes-with-canopenurl.html