简体   繁体   中英

Open an iOS app from a shared link on a Facebook post

We need users to open our app from a "...shared a link" on Facebook, or re-direct to the iOS app download page. Is there objective c code available to accomplish this? Thanks.

Since you asked for objective-C code, I assume you want to open either the appstore or the app on a certain URL. However, objective-c code is the least of the efforts here since it's mostly configurations that are at work for this.

To open an app you need to provide it a custom URL scheme: http://iosdevelopertips.com/cocoa/launching-your-own-application-via-a-custom-url-scheme.html

To detect if that app is installed, you can try that URL: https://developer.apple.com/library/ios/documentation/uikit/reference/UIApplication_Class/index.html#//apple_ref/occ/instm/UIApplication/canOpenURL :

And if not, you can navigate to the appstore instead via a different URL: How can I link to my app in the App Store (iTunes)?

After you have done all that, the only actual code you need takes something of the form:

NSString *customURL = @"yourscheme://";
NSString *storeURL = @"itms://url_to_your_app";

if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:customURL]])
{
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:customURL]];
}
else
{
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:storeURL]];    
}

Opening the app via it's URL can be done from other apps and websites, but will be more difficult to choose whether or not to open the app or store from inside a browser.

Apple have documented the process for you. You can just implement it your way.

NSString *iTunesLink = @"https://itunes.apple.com/us/app/apple-store/id375380948?mt=8";

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:iTunesLink]]

You can refer to This document for more info

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM