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

React Native v0.61.5在Pixel 6上深度链接处理器无法触发

React Native 0.61.5 Pixel 6深度链接监听器不触发问题解决

针对你遇到的RN 0.61.5在Pixel 6上深度链接可打开App但监听器无响应的问题,给你几个适配旧版本的解决办法:

1. 补充冷启动场景的URL处理

RN 0.61.5的Linking模块在App冷启动(完全关闭后通过深度链接打开)时,不会触发url事件,只有热启动(App在后台时打开链接)才会触发。你需要手动获取初始URL并处理:

修改App.js代码:

import { Linking } from 'react-native';

const handleUrlDeepLink = url => {
  if (url) {
    console.log('深度链接URL:', url);
    // 这里添加你的业务逻辑
  }
};

// 处理冷启动时的初始链接
Linking.getInitialURL().then(initialUrl => {
  handleUrlDeepLink(initialUrl);
});

// 监听热启动时的链接事件
Linking.addEventListener('url', handleUrlDeepLink);

2. 修正AndroidManifest配置

Pixel 6搭载Android 12+,RN旧版本对新系统的深度链接适配存在问题,检查AndroidManifest.xml中的MainActivity配置:

  • 添加android:launchMode="singleTask":避免每次打开链接创建新的Activity实例,确保监听器在当前实例生效
  • 新增android:exported="true":Android 12+要求可被外部调用的Activity必须设置该属性

配置示例:

<activity
  android:name=".MainActivity"
  android:launchMode="singleTask"
  android:exported="true">
  <intent-filter>
    <action android:name="android.intent.action.VIEW" />
    <category android:name="android.intent.category.DEFAULT" />
    <category android:name="android.intent.category.BROWSABLE" />
    <!-- 替换为你的App自定义scheme -->
    <data android:scheme="your-app-scheme" />
  </intent-filter>
</activity>

3. 确认日志输出

有时候RN的console.log在部分Android设备上不会直接显示在调试工具面板,建议用adb命令查看日志:

adb logcat -s ReactNative:V ReactNativeJS:V

内容的提问来源于stack exchange,提问作者Eugene

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.30 09:00:23