Is it possible to somehow launch my app using a URL sent via mail? For example I have User profile that user wants to invite their friend into the app. They send an e-mail t
Yes, this is totally possible. You need to register a URL scheme for your app.
Select your app project in Xcode, then click on the target, and from the Info tab, register a new URL scheme.
The identifier is your app identifier as com.company.AppName and the URL Scheme is the name you wish to use, like appName
Now as for the ideal solution, as we are adding this to our app now, you should ideally NOT send links in email with your custom scheme. The reason is that the user might open it from a computer, so this link will not work.
The best scenario is the following:
appname://
Now you send in your emails the links with normal URL's that link to your website and here comes part 2:
If it's present, instead of opening the link from your website, redirect the user to your app, with the proper values, like
appname://mailbox?sender_is=123&user_name=Lefteris
This ensures your email links will always work and that you will open from Mobile Safari the links ONLY if your app has been installed on the device...
Finally, just a note, the URL scheme is appname://
and not http://appname
Now to explain the part 1 better, in our AppDelegate, we can do this in the - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
delegate:
//if user has not set the app installed cookie, set it now.
bool hasAppInstalledCookie = [[NSUserDefaults standardUserDefaults] boolForKey:@"appInstalledCookie"];
if (!hasAppInstalledCookie) {
//mark it was set
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"appInstalledCookie"];
[[NSUserDefaults standardUserDefaults] synchronize];
//open the web browser
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.myApp.com/appInstalled"]];
}
Now in our appInsalled page, (index.html for example), we just set a cookie (any cookie name we want) then we kick the user back to our app, like this:
The reason we are using a cookie, is to use this cookie, when the user opens up an email link. We will check if the browser is mobile safari AND the cookie is installed. This way, we know the user has installed our app, and the redirect will work properly.