SuperAPI AI 工具集

capacitor-deep-linking

测试与质量

查看项目

更新于 10-15 17:31

技能介绍

用途:为 Capacitor 应用接入并调试深度链接,把 myapp:// 自定义 scheme、iOS Universal Links 和 Android App Links 路由进 Web 应用。

触发场景:新增链接方案;链接在浏览器打开而非应用,或打开应用却落在首页;appUrlOpen 在热启动触发但冷启动缺失 URL;升级 Capacitor 8.5+ / 采用 SceneDelegate.swift 后深度链接失效;OAuth、魔法链接、支付重定向需要回到应用;adb shell pm get-app-links 未显示 verified。

主要能力:区分三种链接类型。自定义 scheme(双平台,myapp://product/123,无需托管文件,无归属验证);Universal Links(iOS,https 链接,需 /.well-known/apple-app-site-association,验证归属);App Links(Android 6+,https 链接,需 /.well-known/assetlinks.json,验证归属)。安全敏感场景建议使用已验证的 https 链接。

使用方式:先检查 capacitor.config.*、Info.plist、entitlements、AppDelegate.swift、SceneDelegate.swift、AndroidManifest.xml 与 @capacitor/app 版本。安装并同步:npm install @capacitor/app && npx cap sync。在应用启动(路由渲染前)注册一次处理器,同时使用 appUrlOpen 与 getLaunchUrl();示例:await App.addListener('appUrlOpen', ...) 与 const launch = await App.getLaunchUrl()。自定义 scheme 需在 Info.plist 配置 CFBundleURLTypes,在 AndroidManifest.xml 的 MainActivity 内加 intent-filter。

限制与提示:自定义 scheme 的 URL 第一段会被解析为 host;监听器必须在启动时注册;冷启动可能同时经 getLaunchUrl() 与 appUrlOpen 拿到同一 URL,需去重;导航前应校验并白名单路径,深度链接是不可信输入。验证需在真机运行冷/热启动矩阵,Universal Links 不宜只从模拟器地址栏测试。资料未提供具体收费或版本价格信息。