Swiftのボタンをタップしてfbとinstagramアプリを開く方法
How Open Fb Instagram App Tapping Button Swift
解決:
Swift4およびiOS10以降のアップデート
OK、Swift3でこれを達成するための2つの簡単なステップがあります。
まず、変更する必要がありますリストするInfo.plist
Instagramと
フェイスブック
LSApplicationQueriesSchemes。開くだけ
Info.plistをソースコードとして貼り付けます。
LSApplicationQueriesSchemes instagram fbその後、開くことができますInstagramとを使用してFacebookアプリinstagram://とfb://。これがInstagramの完全なコードであり、Facebookでも同じことができます。このコードを、アクションとして使用している任意のボタンにリンクできます。
@IBAction func InstagramAction(){let Username = 'instagram' //ここにあるInstagramユーザー名letappURL = URL(string: 'instagram:// user?username = (Username)')! let application = UIApplication.shared if application.canOpenURL(appURL){application.open(appURL)} else {// Instagramアプリがインストールされていない場合は、Safari内でURLを開きますlet webURL = URL(string: 'https:// instagram。 com / (ユーザー名) ')! application.open(webURL)}}にとってFacebook、あなたはこのコードを使うことができます:
appURL = URL(string: 'fb:// profile / (Username)')!
これらのリンクを見てください、それはあなたを助けることができます:
https://instagram.com/developer/mobile-sharing/iphone-hooks/
http://wiki.akosma.com/IPhone_URL_Schemes
iOSのネイティブFacebookアプリでFacebookリンクを開く
それ以外の場合は、特定のプロファイル(ニックネーム:johndoe)を開くためのInstagramの簡単な例がここにあります:
var instagramHooks = 'instagram:// user?username = johndoe' var instagramUrl = NSURL(string:instagramHooks)if UIApplication.sharedApplication()。canOpenURL(instagramUrl!){UIApplication.sharedApplication()。openURL(instagramUrl!)} else { //ユーザーがInstagramUIApplication.sharedApplication()。openURL(NSURL(string: 'http://instagram.com/')!)を持っていないため、safariにリダイレクトします}
迅速な3で;
まず、これをInfo.plistに追加する必要があります
このコードを使用できるよりも;
let instagramUrl = URL(string: 'instagram:// app')UIApplication.shared.canOpenURL(instagramUrl!)UIApplication.shared.open(instagramUrl!、options:[:]、completionHandler:nil)