Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Url scheme : Open app or Appstore from mail

I'm creating an application where users can share data by sending emails to each other. In this mail there is a link to my app (I created an URL scheme for my app) But, if the users doesn't have my application on his iPhone, then when he clicks on the link, nothing happens.

My question : How could I do to launch my app when the application is installed on the user's iPhone and launch the Appstore or a website if this application is not installed

Thank you

like image 848
Titouan de Bailleul Avatar asked May 11 '12 20:05

Titouan de Bailleul


1 Answers

canOpenURL is what you're looking for.

Here is an example for launching twitter app:

NSURL* twitterURL = [NSURL URLWithString:[NSString stringWithFormat:@"twitter:@%@", twitterUser]];

if ([[UIApplication sharedApplication] canOpenURL:twitterURL]) {
    [[UIApplication sharedApplication] openURL:twitterURL];
} else {
    NSURL* url = [NSURL URLWithString:@"http://itunes.apple.com/us/app/twitter/id333903271?mt=8"];
    [[UIApplication sharedApplication] openURL:url];
}   

EDIT

If you want do do this from a webpage or html email, you find your answer here: https://stackoverflow.com/a/627942/550177

and here: https://stackoverflow.com/a/1109200/550177

like image 71
Felix Avatar answered Sep 30 '22 01:09

Felix