Skip to content

Latest commit

 

History

History
104 lines (82 loc) · 2.85 KB

Note_00111_20151223.md

File metadata and controls

104 lines (82 loc) · 2.85 KB

变更记录

序号 录入时间 录入人 备注
1 2015-05-07 Alfred Jiang -
2 2015-12-23 Alfred Jiang -

方案名称

应用间通信 - 通过 URL 检测是否安装并打开应用

关键字

应用间通信 \ URL \ Web \ 邮件打开App \ Schema

需求场景

  1. 需要通过 URL 检测是否安装应用,如果已安装则打开应用,如果未安装则跳转到下载页面

参考链接

  1. iOS使用schema协议调起APP
  2. 在mobile safari中巧妙实现检测应用安装就打开,否则进App Store下载
  3. CSDN - IOS在一个程序中启动另一个程序

详细内容

1. App 设置

在 .plist 文件添加如下字段

Image_00111_00001

    <key>CFBundleURLTypes</key>
    <array>
        <dict>
            <key>CFBundleURLName</key>
            <string></string>
            <key>CFBundleURLSchemes</key>
            <array>
                <string>GJApplication</string>
            </array>
        </dict>
    </array>
  • GJApplication 替换为自定义名称
2. Web 代码
  1. 示例一
<body>
<div>
Click to open GJ App
<br />
<a href="REXApplication://com.acme.ToDoList"></a>
<a onClick="javascript:try_to_open_app();" href="REXApplication://com.acme.ToDoList">Open GJ App</a>
</div>
<script language="javascript">
var timeout;
function open_appstore() {
window.location='http://itunes.apple.com/cn/app/id950554426?mt=8';
}

function try_to_open_app() {
timeout = setTimeout('open_appstore()', 300);
}
</script>
</body>
  1. 示例二
 <!DOCTYPE html>
<html>
    <body>
        <script type="text/javascript">
            window.onload = function() {
                // Deep link to your app goes here
                document.getElementById("l").src = "REXApplication://";

                setTimeout(function() {
                    // Link to the App Store should go here -- only fires if deep link fails
                    window.location = "http://www.pgyer.com/irex";
                }, 300);
            };
        </script>
        <iframe id="l" width="1" height="1" style="visibility:hidden"></iframe>
    </body>
</html>
3. 测试链接
  1. 测试链接一
  2. 测试链接二

效果图

(无)

备注

(无)