How to open app or open link using a single button from email?

左心房为你撑大大i 提交于 2019-12-25 08:29:30

问题


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:


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.


来源:https://stackoverflow.com/questions/42406992/how-to-open-app-or-open-link-using-a-single-button-from-email

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!