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

React Native Expo生产环境Deep Linking失效及分享链接问题咨询

解决React Native Expo生产环境Deep Linking及通用分享链接问题

1. 完善生产环境Deep Linking配置

首先确保app.json里的生产环境配置正确,替换开发阶段的临时配置:

  • 自定义Scheme配置:在expo根节点下添加生产用的scheme,比如你的myapp:
    {
      "expo": {
        "scheme": "myapp",
        // 其他基础配置...
        "android": {
          "intentFilters": [
            {
              "action": "VIEW",
              "data": [
                {
                  "scheme": "myapp",
                  "host": "*",
                  "pathPrefix": "/"
                }
              ],
              "category": ["BROWSABLE", "DEFAULT"]
            }
          ]
        },
        "ios": {
          "associatedDomains": ["applinks:yourdomain.com"]
        }
      }
    }
    
  • Universal Links配置:如果需要用HTTPS链接实现跨平台通用跳转,需配置:
    • 安卓:在你的域名根目录的.well-known文件夹下放置assetlinks.json,内容示例:
      [{
        "relation": ["delegate_permission/common.handle_all_urls"],
        "target": {
          "namespace": "android_app",
          "package_name": "com.yourcompany.myapp",
          "sha256_cert_fingerprints": ["你的安卓正式签名SHA256指纹"]
        }
      }]
      
    • iOS:在相同位置放置apple-app-site-association文件(无后缀),内容示例:
      {
        "applinks": {
          "apps": [],
          "details": [{
            "appID": "你的苹果开发者TeamID.com.yourcompany.myapp",
            "paths": ["/*"]
          }]
        }
      }
      

2. 动态适配环境生成分享链接

分享代码不能硬编码本地开发的exp://地址,要根据运行环境自动切换:

import { Platform } from 'react-native';

// 生成对应环境的Deep Link
const generateShareLink = (productId) => {
  if (__DEV__) {
    // 开发环境用本地Expo服务地址
    const debuggerHost = Expo.manifest?.debuggerHost?.split(':').shift();
    return `exp://${debuggerHost}:19000/--/ProductScreen?id=${productId}`;
  } else {
    // 生产环境优先用Universal Links(已配置前提下),否则用自定义Scheme
    const useUniversalLinks = true;
    if (useUniversalLinks) {
      return `https://yourdomain.com/ProductScreen?id=${productId}`;
    } else {
      return `myapp://ProductScreen?id=${productId}`;
    }
  }
};

3. 生产环境验证方法

  • 自定义Scheme测试:安装正式打包的APK/IPA后,用命令验证(确保设备已安装目标应用):
    # 安卓测试
    npx uri-scheme open myapp://ProductScreen?id=95bcc346-9da6-4eff-a45e-6012e83df27b --android
    # iOS测试
    npx uri-scheme open myapp://ProductScreen?id=95bcc346-9da6-4eff-a45e-6012e83df27b --ios
    
  • Universal Links测试:直接在设备浏览器中打开https://yourdomain.com/ProductScreen?id=xxx,验证是否自动跳转到应用内对应页面。

4. 常见问题排查

  • 确认打包时app.json的配置已被正确注入到应用中(Expo打包会自动读取这些配置);
  • 检查域名的.well-known文件是否可公开访问(用浏览器直接访问对应URL,确保返回正确JSON格式);
  • 安卓需确认正式签名的SHA256指纹与assetlinks.json中的配置一致;
  • iOS需确认开发者后台已开启Associated Domains权限,且apple-app-site-association中的TeamID、AppID完全匹配。

内容的提问来源于stack exchange,提问作者Cem Bıçakcı

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.11 01:42:19