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 that has some url like:
join me via this link:
http://appname?sender_id=25&some_other_value=something
and opening that link from the iPhone would bring user into the application and would let me parse those values.
Is that possible?
Once you build a link with same signature as mentioned in manifest The android system will add your app in chooser to open link in your app and you will get the data in "getIntent(). getData()" in respective Activity. If app is not installed the link will itself open in browser. Then handle it on browser .
On your iOS device, you can share an app directly from the App Store by finding and clicking on the application you want, then scrolling down to "Tell a Friend" which lets you send an email with a link to the application.
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:
<script type="text/javascript">
window.location = 'appName://';
</script>
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With