Reputation: 23419
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?
Upvotes: 29
Views: 29537
Reputation: 11
In case you are using Flutter, you can use the package url_launcher for this purpose.
Use the uri scheme itms-beta://
Here is the function you can use:
Future<void> openTestFlight() async {
final Uri testFlightUri = Uri.parse('itms-beta://');
try {
if (await canLaunchUrl(testFlightUri)) {
await launchUrl(testFlightUri);
} else {
// If TestFlight isn't installed, open App Store to download it
final Uri appStoreUri = Uri.parse('https://apps.apple.com/app/testflight/yourAppleAppId');
if (await canLaunchUrl(appStoreUri)) {
await launchUrl(appStoreUri);
} else {
throw 'Could not launch TestFlight or App Store';
}
}
} catch (e) {
print('Error launching TestFlight: $e');
}
}
Upvotes: 0
Reputation: 104
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)
}
Upvotes: 3
Reputation: 4066
Swift 3/4 answer:
if let customAppURL = URL(string: "itms-beta://"){
if(UIApplication.shared.canOpenURL(customAppURL)){
UIApplication.shared.open(customAppURL, options: [:], completionHandler: nil)
}
}
Upvotes: 8
Reputation: 22701
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>
Upvotes: 50
Reputation: 7778
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.
Upvotes: 2
Reputation: 2875
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];
}
Upvotes: 9
Reputation: 2223
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
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]]];
}
Upvotes: 6