You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

移动端检测应用安装状态:实现跳转应用商店或唤起APP

移动端网页检测APP是否安装并跳转的实现方案

核心思路

网页无法主动检测APP是否安装,只能通过链接跳转的行为反馈判断:

  • 若APP已安装,系统会直接唤起应用;
  • 若未安装,跳转行为失败,此时引导用户前往应用商店。

以下分iOS和Android给出具体实现方案,结合你现有代码修改:


iOS 实现:使用 Universal Links(推荐)

Universal Links 是苹果官方方案,无需依赖定时器判断,体验更流畅。

  1. 前置配置:
    • 开发者在苹果后台配置网站域名作为关联域名
    • 在网站根目录放置无后缀的 apple-app-site-association 文件,指定应用Bundle ID和跳转路径
  2. 网页逻辑:
    直接将链接设为你的Universal Links,用户点击时:
    • 已装应用会被系统自动唤起;
    • 未装则跳转到该链接指向的App Store页面(可将Universal Links目标设为商店地址)

Android 实现:两种方案可选

方案1:App Links(推荐,Android 6.0+)

和iOS Universal Links原理一致,配置后无需定时器:

  1. 前置配置:
    • 应用内配置对应的intent-filter,声明支持的域名
    • 网站根目录放置 assetlinks.json 文件,验证应用与域名的关联
  2. 网页逻辑:直接使用对应链接,系统自动处理唤起或跳商店逻辑

方案2:自定义URL Scheme + 超时判断(兼容低版本)

若需兼容Android 6.0以下,可使用自定义Scheme配合定时器判断是否唤起成功:

  • 先尝试打开APP的Scheme链接,超时未成功则跳转Google Play

整合后的完整代码示例

<a id="app_link" href="#" onclick="handleAppRedirect()">continue in the app</a>

<script>
function handleAppRedirect() {
    const userAgent = navigator.userAgent;
    let appTargetUrl = '';
    let storeUrl = '';

    // 检测设备系统
    if (/iphone|ipad/i.test(userAgent)) {
        appTargetUrl = 'your-app-universal-link://path'; // 替换为你的Universal Links或Scheme
        storeUrl = 'https://apps.apple.com/app/myapp';
    } else if (/android/i.test(userAgent)) {
        appTargetUrl = 'your-app-scheme://path'; // 替换为你的App Links或Scheme
        storeUrl = 'https://play.google.com/store/apps/myapp';
    } else {
        return; // 非移动设备,不处理
    }

    // 处理跳转逻辑
    if (/android/i.test(userAgent)) {
        // Android用定时器判断Scheme是否唤起成功
        const startTime = Date.now();
        window.location.href = appTargetUrl;
        
        setTimeout(() => {
            if (Date.now() - startTime < 1500) { // 1.5秒内未唤起则判定为未安装
                window.location.href = storeUrl;
            }
        }, 1000);
    } else {
        // iOS用Universal Links直接跳转,系统自动处理
        window.location.href = appTargetUrl;
        // 备用:若用Scheme,可添加定时器降级跳商店
        // setTimeout(() => {
        //     window.location.href = storeUrl;
        // }, 1000);
    }
}
</script>

注意事项

  • 优先使用系统级链接方案:Universal Links/App Links是系统级跳转,比Scheme更可靠,不会出现弹窗询问
  • Scheme跳转的局限性:iOS 9+ 对未安装应用的Scheme跳转无响应,需依赖定时器;部分Android浏览器可能拦截Scheme跳转
  • 避免自动触发跳转:尽量让用户主动点击按钮触发,防止被浏览器判定为恶意跳转

内容的提问来源于stack exchange,提问作者streaming-coc

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.19 00:37:36