Reputation: 23
I have a project in which I have to open an app from within the other app. I am able to open the other app through URL schema but now I have to do add one more functionality that if the other app is not installed in the mobile phone then it should redirect the user to the AppStore link of that app.
NSString *appLink = @"otherApp://";
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:appLink]];
The code above opens up the other app but how can I check whether the app in installed in phone or not, so that I can redirect the user to the AppStore link of the other app if it is not installed.
Although I know how to open appstore from within app but problem is how to check if the app is installed or not. The URL for opening an app in appstore is: itms://itunes.apple.com/in/app/otherApp/id134567414?mt=8
Upvotes: 0
Views: 1176
Reputation: 4879
Yes, it is actually easy. use:
NSString *appLink = @"otherApp://";
if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:appLink]]) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:appLink]];
} else {
[[UIApplication sharedApplication] openURL:[NSURL @"itms://itunes.apple.com/in/app/otherApp/id134567414?mt=8"]];
}
Upvotes: 3