2017-06-17 65 views
-1

與參數打開一個URL,如果你從我的應用程序 點擊例如某人的Instagram的按鈕,你會在配置文件中打開鏈接instagram://app/用戶名如何Swift3

比方說,一個用戶把「mark20」作爲Instagram的用戶名 您打開鏈接instagram://app/mark20/

我想用顯示'mark20'打開instagram。目前它是開放的Instagram新聞提要,但沒有打開'mark20'個人資料。我想按鈕,點擊打開Instagram的用戶個人資料頁

例如

enter image description here

我如何能做到這一點

func shareToInstagram() { 

     //let instagramURL = URL(string: "instagram://app/") 
     //not working anymore 
     let instagramURL = URL(string: "instagram://app/mark20/") 
     if (UIApplication.shared.canOpenURL(instagramURL! as URL)) { 

      UIApplication.shared.open(instagramURL!, options: ["":""], completionHandler: nil) 

     } else { 
      print(" Instagram isn't installed ") 
     } 
    } 
+0

什麼是不工作? – sasquatch

+0

我想打開顯示'mark20'的instagram。目前它是開放的Instagram新聞饋送,但沒有顯示'mark20'個人資料 –

回答

1

是啊,我找出工作的問題path parameter不再工作,但query parameter

func shareToInstagram() { 

     let instagramURL = URL(string: "instagram://user?username=mark20") 

     if (UIApplication.shared.canOpenURL(instagramURL! as URL)) { 


      UIApplication.shared.open(instagramURL!, options: ["":""], completionHandler: nil) 

      print("miss you so much ") 


     } else { 
      print(" Instagram isn't installed ") 
     } 
    } 

更多檢查此鏈接instagram iPhone Hooks

2

斯威夫特

var instagramAppURL = URL(string: "instagram://user?username=USERNAME") 
     if UIApplication.shared.canOpenURL(instagramAppURL!) { 
      UIApplication.shared.openURL(instagramAppURL!) 
     } 

的OBJÇ

NSURL *instagramAppURL = [NSURL URLWithString:@"instagram://user?username=USERNAME"]; 
if ([[UIApplication sharedApplication] canOpenURL:instagramAppURL]) { 
    [[UIApplication sharedApplication] openURL:instagramAppURL]; 
} 

首先,你必須修改Info.plist中列出的Instagram和Facebook與LSApplicationQueriesSchemes。只需打開Info.plist中的源代碼,並粘貼此:

<key>LSApplicationQueriesSchemes</key> 
<array> 
    <string>instagram</string> 
    <string>fb</string> 
</array> 

有關詳細信息和更多的方式請參考以下鏈接 https://www.instagram.com/developer/mobile-sharing/iphone-hooks/