如何在iOS现有应用中实现Deferred Deep Linking?
iOS Deferred Deep Linking 通用实现方案
下面提供两种通用实现思路,覆盖「已安装直接唤起App、未安装引导到App Store」的核心需求:
一、自建Web中转页面方案(快速落地)
这种方式无需依赖苹果官方配置,通过一个Web页面做中转判断:
- 准备专属中转链接(比如
https://your-domain.com/deeplink) - 在该页面嵌入JavaScript逻辑,先尝试唤起App,失败则跳转App Store:
function handleRedirect() { // 替换为你的App Scheme和App Store链接 const appSchemeUrl = 'yourapp://product/123'; const appStoreUrl = 'https://apps.apple.com/cn/app/你的应用名称/id你的AppID'; // 用iframe尝试唤起App(规避部分浏览器的弹窗拦截) const iframe = document.createElement('iframe'); iframe.style.display = 'none'; iframe.src = appSchemeUrl; document.body.appendChild(iframe); // 1秒后判断唤起状态,未成功则跳转App Store setTimeout(() => { window.location.href = appStoreUrl; document.body.removeChild(iframe); }, 1000); } window.addEventListener('load', handleRedirect);
- iOS端配置:在Xcode的
Info.plist中添加LSApplicationQueriesSchemes数组,将你的App Scheme(比如yourapp)加入其中,允许App被外部唤起。
注意:部分浏览器可能拦截Scheme唤起,中转页面会有短暂空白,体验略逊于官方方案。
二、苹果Universal Links方案(原生优雅体验)
这是苹果官方推荐的深度链接方案,无需中转页面,系统直接处理跳转逻辑:
1. 配置Universal Links
- 登录苹果开发者后台,给你的App开启
Associated Domains能力,添加applinks:your-domain.com(替换为你的域名) - 在你的域名根目录上传
apple-app-site-association文件(无后缀),内容示例:
{ "applinks": { "apps": [], "details": [ { "appID": "你的TeamID.你的AppBundleID", "paths": ["/deeplink/*"] } ] } }
- 验证配置:可通过苹果官方工具确认文件有效性。
2. 处理App内跳转
当用户已安装App时,点击Universal Links会直接唤起App,你需要在App中接收链接并处理跳转:
- 在
SceneDelegate(或AppDelegate,适配iOS13以下)中实现方法:
func scene(_ scene: UIScene, continue userActivity: NSUserActivity) { guard userActivity.activityType == NSUserActivityTypeBrowsingWeb, let deepLinkUrl = userActivity.webpageURL else { return } // 解析链接参数,跳转到对应页面 navigateToTargetPage(url: deepLinkUrl) }
3. 未安装时的引导
当用户未安装App时,点击Universal Links会自动打开链接对应的Web页面,你只需将该页面设置为引导下载页(直接跳转App Store即可)。
4. 延迟深度链接的参数传递
如果需要跟踪用户点击链接后隔段时间才下载的场景:
- 在Universal Links中带上业务参数(比如
https://your-domain.com/deeplink?inviteCode=1234) - 用户下载后首次打开App,通过
continueUserActivity拿到完整URL,解析参数后跳转对应页面; - 若需跨设备/长期跟踪,可在用户点击链接时,将设备标识(如IP、UA)和参数存入后端,App首次启动时上报设备标识,后端返回对应参数后处理跳转。
两种方案对比
- 自建中转页:实现成本低,无需开发者后台配置,但体验有瑕疵,存在拦截风险;
- Universal Links:系统级唤起,体验流畅,但需要域名配置和开发者后台操作,步骤稍繁琐。
内容的提问来源于stack exchange,提问作者Abhistin
相关产品推荐
相关产品推荐

