SuperAPI AI 工具集

universal-links-deep-linking

前端与建站

查看项目

更新于 10-15 22:15

技能介绍

用途:让普通 https 链接在已安装应用时由系统直接打开原生 iOS 或 Expo/React Native 应用,未安装时加载同一网页作为回退,无需检测跳转或弹窗。

主要能力:Universal Link(iOS)/ App Link(Android)是经系统验证的双向握手。网站托管 apple-app-site-association(iOS)与 assetlinks.json(Android)为应用背书;应用声明拥有该域名(entitlement / associatedDomains / intentFilter);系统在安装时验证配对,之后同一 https URL 服务两类用户。

使用方式:需配置三个层面。网站侧:/.well-known/apple-app-site-association(JSON,application/json,无重定向)与 /.well-known/assetlinks.json。应用侧:iOS 用 applinks:HOST entitlement 或 Expo 的 ios.associatedDomains;Android 用 autoVerify intent filter 或 android.intentFilters。链接处理:iOS 用 onOpenURL + NSUserActivityTypeBrowsingWeb,Android 用 onNewIntent / Linking。AASA 的 App ID 为 <TEAM_ID>.<BUNDLE_ID>;assetlinks 指纹为签名证书 SHA-256(开发用 debug keystore,生产用 Play App Signing 证书)。

适用场景:需要从消息、笔记等点击 https 链接直达应用内对应内容,同时保留网页回退与安装引导。

限制与注意:失败是静默的,链接只会打开浏览器。AASA URL 或链接上的重定向会破坏验证,iOS 不跟随重定向,apex→www 是典型陷阱,须统一使用终端主机。AASA 内容类型必须为 application/json。需在真机上点击链接测试,模拟器不可靠,Safari 地址栏输入会绕过 Universal Links。Apple 会缓存 AASA,开发期可用 applinks:HOST?mode=developer(仅 Debug,切勿上线)。Android 签名指纹须与安装包一致,否则 autoVerify 静默失败。Associated Domains 需在 Apple 开发者门户为 App ID 启用(付费账号)。验证命令:curl -sI https://HOST/.well-known/apple-app-site-association、curl -s https://app-site-association.cdn-apple.com/a/v1/HOST、curl -s https://HOST/.well-known/assetlinks.json、adb shell pm get-app-links YOUR.PACKAGE.NAME。网页回退需渲染真实页面并加“Get the app”CTA,iOS 可加 Smart App Banner(<meta name="apple-itunes-app" content="app-id=...">);无法解析的 id 应返回优雅的 404/空状态。具体文件模板与各技术栈步骤见 references/setup-and-gotchas.md。