1
votes

I need to implement a feature where I can open either a web page or the app from an email account.

For Example: I have an app in which whenever I view any user's profile, the user receives an email. The mail contains a button "See Profile", the functionality for that button is whenever the button is tapped, it should open a mobile friendly site.

Now, my client requires that if the app is already installed, then tapping the button should open the associated app and it should navigate to the profile.

Also, if the user opens his email on a desktop, then a web site should be opened on tapping the button.

On mobile side, I think this could be done by URL scheme, but how to associate the same button for 2 different functionalities.

Instagram is already doing it.

Please help!

1
May be help you from this link : stackoverflow.com/questions/25940109/…iParesh
@iParesh No, thats not the case.Jassi
You need to use a universal link - developer.apple.com/ios/universal-linksPaulw11
@Paulw11 : it's worth mentioning that this is available since iOS 9.Losiowaty

1 Answers

1
votes

I came up with a simple solution but it needs your server help, - Add a following html file in your server (update with your app urlscheme,itunes link & website url.)

<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="content-type" content="text/html" />
<meta name="author" content="gencyolcu" />
<title>Social Media Share</title>
<script>    
 function openProfile() {
    var userAgent = navigator.userAgent || navigator.vendor || window.opera;
    if( userAgent.match( /iPad/i ) || userAgent.match( /iPhone/i ) || userAgent.match( /iPod/i ) )
    {
        window.location.href = "appurlscheme://;
        setTimeout(function () { 
        window.location = "https://itunes.apple.com/us/app/yourApp/id593274564?ls=1&mt=8";}, 25);
    }
    else
    {
        window.location = "https://www.google.co.in/?gfe_rd=cr&ei=sLSuWM4B7MjwB-6LtagE"
    }
}

</script>
</head>
<body onload="openProfile()"></body>
</html>
  • Let us assume http://dev46.com/testfile/ this is your html file url.Email you are sending will be a html page right, So while clicking See Profile hit the above url.
  • Above html code is straight forward,It checks whether user comes from iPhone,iPad or iPod if it so it tries to open you apps urlscheme if available otherwise it will open Appstore.
  • If it is not an iphone it will open your web site.
  • I had tested above method it's working fine,give it a try.