2017-06-01 85 views
0

当用户按下邮件链接,然后如何在iPhone中打开已安装的应用程序,如果没有安装,那么如何重定向到应用商店链接?从邮件链接打开iOS应用

回答

4

添加以下行到你的plist文件:(DemoTest是我的自定义URL方案)

<key>CFBundleURLTypes</key> 
    <array> 
     <dict> 
      <key>CFBundleURLName</key> 
      <string>DemoTest</string> 
      <key>CFBundleURLSchemes</key> 
      <array> 
       <string>DemoTest</string> 
      </array> 
     </dict> 
    </array> 

然后尝试打开DemoTest://从浏览器的URL,它会问你打开安装该应用程序。

enter image description here

HTML代码:

<html> 
    <body> 
     <script type="text/javascript"> 
      window.onload = function() { 
       // Deep link to your app goes here 
       document.getElementById("l").src = "DemoTest://"; 

       setTimeout(function() { 
        // Link to the App Store should go here -- only fires if deep link fails     
        window.location = "https://itunes.apple.com/us/app/my.app/id123456789?ls=1&mt=8"; 
       }, 500); 
      }; 
     </script> 
     <iframe id="l" width="1" height="1" style="visibility:hidden"></iframe> 
    </body> 
</html> 
+0

出于好奇:这应该直接从邮件打开应用程序,对吧?或者它会一直打开Safari,然后转换到应用程序? – LinusGeffarth

+0

它会首先重定向到safari,然后“DemoTest://”URL检查是否安装了应用程序。 –

+0

@LinusGeffarth这里是HTML代码: –