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

React Native后台服务通知点击默认打开图库 需跳转至自身应用

react-native-background-actions 通知跳转及iOS运行问题修复

Android端点击通知打开图库问题

问题原因

通知点击跳转异常是因为主Activity启动intent-filter配置缺失/错误,系统匹配到了图库应用的启动规则,没有正确识别到你的应用入口。

修复步骤

  1. 修正android/app/src/main/AndroidManifest.xml中主Activity的配置,必须保留默认启动过滤器,自定义deep link不要替换默认启动规则,正确配置如下:
<activity
  android:name=".MainActivity"
  android:label="@string/app_name"
  android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|screenSize|smallestScreenSize|uiMode"
  android:launchMode="singleTask"
  android:windowSoftInputMode="adjustResize"
  android:exported="true">
  <!-- 核心:必须保留MAIN+LAUNCHER过滤器,这是应用启动入口的标识 -->
  <intent-filter>
      <action android:name="android.intent.action.MAIN" />
      <category android:name="android.intent.category.LAUNCHER" />
  </intent-filter>

  <!-- 自定义deep link过滤器,不要替换上面的默认启动过滤器 -->
  <intent-filter android:label="filter_react_native">
      <action android:name="android.intent.action.VIEW" />
      <category android:name="android.intent.category.DEFAULT" />
      <category android:name="android.intent.category.BROWSABLE" />
      <!-- 替换为你的应用专属scheme,不要用http/https/file这类通用scheme,避免和其他应用冲突 -->
      <data android:scheme="myapp" />
  </intent-filter>
</activity>
  1. 补全后台任务初始化options配置,增加linking字段指定跳转目标:
const options = {
    taskName: 'Example',
    taskTitle: 'ExampleTask title',
    taskDesc: 'ExampleTask description',
    taskIcon: {
        name: 'ic_launcher',
        type: 'mipmap',
    },
    color: '#ff00ff',
    parameters: {
        delay: 1000,
    },
    taskProgressBarOptions:{
        max: 100,
        value: 80,
    },
    // 新增配置:指定点击通知跳转的uri,替换为你自己的包名对应scheme
    linking: {
        uri: 'myapp://taskpage'
    }
};

注意事项

  • 修改配置后必须卸载设备上的旧安装包,重新打包安装,清除系统旧的intent缓存规则
  • android:exported="true"属性必须配置,否则Android 12及以上版本无法通过外部通知唤起Activity

iOS端模块无法运行问题

该问题和真机调试环境无关,是iOS系统机制和库本身的实现限制导致:

  • iOS系统不支持Android式的无限制常驻后台任务,仅对音频播放、持续定位、VoIP、蓝牙通信等特定场景开放后台权限
  • 必须在Xcode中开启对应场景的Background Modes权限,同时在Info.plist中声明对应的后台能力,否则应用退到后台后任务会在30秒内被系统挂起
  • 如果你没有使用上述系统允许的后台场景,该库在iOS端无法实现常驻后台运行,属于系统限制,没有通用绕过方案

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.09.01 23:09:41