28

How do i find the scheme of another app and deep link to it from my own iOS app?

More specifically, I want to deep link to the Testflight app upon certain conditions (set by my code). I'm assuming the person has Testflight installed, (which might be a bad assumption but we can live with that assumption).

I know that on Android, you can query for apps and send intents to deep link to someone else's app. What would be the equivalent on iOS?

picciano
  • 22,341
  • 9
  • 69
  • 82
David T.
  • 22,301
  • 23
  • 71
  • 123
  • Is there any solution for React-native to achieve same thing ? `Linking.canOpenURL(config.testFlightUrl) .then(supported => { if (!supported) { console.log("Unable to Open Url"); } else { return Linking.openURL(config.testFlightUrl); } }) .catch(err => console.error("Unable to Open Url", err));` – Sriram C G Jun 25 '18 at 09:17

6 Answers6

45

There are two things you need to do. First, check to see if TestFlight is installed. Then create a new link to your app.

NSURL *customAppURL = [NSURL URLWithString:@"itms-beta://"];
if ([[UIApplication sharedApplication] canOpenURL:customAppURL]) {

    // TestFlight is installed

    // Special link that includes the app's Apple ID
    customAppURL = [NSURL URLWithString:@"https://beta.itunes.apple.com/v1/app/978489855"]; 
    [[UIApplication sharedApplication] openURL:customAppURL];
}

This special https://beta.itunes.apple.com URL will be opened directly in TestFlight.

Finally, if you are using iOS 9 (or later), you need to make an addition to your Info.plist to get the canOpenURL: method to work.

If your app is linked on or after iOS 9.0, you must declare the URL schemes you want to pass to this method. Do this by using the LSApplicationQueriesSchemes array in your Xcode project’s Info.plist file. For each URL scheme you want your app to use with this method, add it as a string in this array.

<key>LSApplicationQueriesSchemes</key>
<array>
    <string>itms-beta</string>
</array>
picciano
  • 22,341
  • 9
  • 69
  • 82
  • 1
    how do i get customAppURL? my app is uploaded to testFlight but i couldn't find a way to get the url. – Paragon Oct 21 '15 at 16:16
  • 5
    It's just `https://beta.itunes.apple.com/v1/app/` followed by the app id. Note that this is not documented anywhere and may be subject to change at any time. – picciano Oct 21 '15 at 16:52
  • This opens Testflight and shows our beta App icon (with an open link), however how can one open the beta App directly from a link? – Mark Shust at M.academy Oct 29 '15 at 15:52
  • 1
    it seems this does not work on iOS 10.3? It correctly opens Safari on a TestFlight page, but it does not open TestFlight app... – Altimac Aug 02 '17 at 13:45
  • 5
    @Altimac it looks like the direct deep links work now. Invoke the app directly with the protocol: `itms-beta://beta.itunes.apple.com/v1/app/978489855` – dberwick Aug 02 '17 at 19:33
  • This works great, I want to go one step further by providing an URL that goes directly to a specific build. Is that even possible? `https://beta.itunes.apple.com/v1/app/978489855/1.0/2321` Unfortanltly does not work. – MQoder Jan 07 '19 at 22:57
  • Don't need add item in LSApplicationQueriesSchemes and openURL: works. Tested on iOS 14. – Gon Apr 13 '21 at 08:48
9

From looking at the plist the URL scheme for TestFlight is "itms-beta://" I can't manage to get it deep linking yet, I've tried passing it the Apple ID, with and without a ? along with prefixing it with appleid= I will try bundle ID next.

To open the TestFlight app on the users device you can use:

NSURL *customAppURL = [NSURL URLWithString:@"itms-beta://"];
if ([[UIApplication sharedApplication] canOpenURL:customAppURL]) {
    [[UIApplication sharedApplication] openURL:customAppURL];
}
picciano
  • 22,341
  • 9
  • 69
  • 82
Gary Riches
  • 2,847
  • 1
  • 22
  • 19
8

Swift 3/4 answer:

if let customAppURL = URL(string: "itms-beta://"){
    if(UIApplication.shared.canOpenURL(customAppURL)){
        UIApplication.shared.open(customAppURL, options: [:], completionHandler: nil)
    }
}
JP Aquino
  • 3,946
  • 1
  • 23
  • 25
6

Most of the built-in applications Apple provides respond to custom URL schemes; for example, the Maps, Mail, YouTube, iTunes, and App Store applications will all open in response to custom URLs. However, there are also many established third-party applications with published URL schemes that you can use in your own application. You can search the applications schemes on

  1. http://handleopenurl.com/

  2. http://wiki.akosma.com/IPhone_URL_Schemes – both have a great list of URL schemes

Once you got the custom URL scheme then you can deep link to that app using the same schema,

NSURL *customAppURL = [NSURL URLWithString:@"urlscheme://"];
//Eg: NSURL *whatsappURL = [NSURL URLWithString:@"whatsapp://send?text=Hello%20World!"];
if ([[UIApplication sharedApplication] canOpenURL:whatsAppURL]) {
    [[UIApplication sharedApplication] openURL:whatsAppURL]]];
}
christijk
  • 1,753
  • 18
  • 26
2

Another way to invoke either one app or another:

- (IBAction)go:(id)sender {
    NSString *cnnAppURL = @"cnn://";
    NSString *mapsAppURL = @"maps://";

    BOOL canOpenURL = [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:cnnAppURL]];

    NSString *url = canOpenURL ? cnnAppURL : mapsAppURL;
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];


}

Please read "UseYourLoaf's recent blog post on using URLschemes with canOpenURL. This relates to new security concerns and solutions. Quote:

"This is useful but developers including Twitter and Facebook were using this mechanism to discover the list of Apps installed on a device so they can deliver “tailored content”. Apple decided this is a privacy violation and so in iOS 9 restricted the querying of URL schemes. If you build and link against the iOS 9 SDK you need to whitelist the schemes your app will query. What is important to understand is that this policy can also impact older Apps that have not yet been rebuilt with the iOS 9 SDK."

Please read this link on issues related to the canOpenURL function

Read @picciano's last point - this won't work without modifying your app's plist.

ICL1901
  • 7,632
  • 14
  • 90
  • 138
2

A Swift update to the best response.

I would add that it still works as of iOS 16.
And that it's relevant to open the URL even with TestFlight not installed (it will open in Safari, suggesting to install TestFlight).

// Special scheme specific to TestFlight
let presenceCheck = URL(string: "itms-beta://")!
// Special link that includes the app's ID
let deepLink = URL(string: "https://beta.itunes.apple.com/v1/app/<app-id>")!
let app = UIApplication.shared
if app.canOpenURL(presenceCheck) {
    app.open(deepLink)
}
HangarRash
  • 7,314
  • 5
  • 5
  • 32
PierreMB
  • 94
  • 4