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

React Native集成App Center Push与Google登录后推送仅前台接收问题

解决React Native Android中App Center Push与Google Sign-In的推送冲突问题

我之前在项目里也碰到过一模一样的问题——同时集成App Center Push和react-native-google-signin后,应用后台接收不到推送通知,根源就是com.google.gms.google-services插件自动注入的Firebase组件覆盖了App Center的相关配置。下面是亲测有效的解决方案:

1. 手动在AndroidManifest.xml中保留并配置两个模块的组件

打开android/app/src/main/AndroidManifest.xml,在<application>标签内手动添加App Center的PushReceiver和TokenService,同时保留Firebase的组件,并且调整Intent Filter的优先级,确保App Center的推送逻辑能被优先触发:

<!-- 保留Google Sign-In所需的Firebase组件 -->
<receiver android:name="com.google.firebase.iid.FirebaseInstanceIdReceiver" 
          android:permission="com.google.android.c2dm.permission.SEND" 
          android:exported="true">
    <intent-filter>
        <action android:name="com.google.android.c2dm.intent.RECEIVE" />
        <category android:name="se.crossplatform.parkeraapp" />
    </intent-filter>
</receiver>
<service android:name="com.google.firebase.iid.FirebaseInstanceIdService" 
         android:exported="true">
    <intent-filter android:priority="-500">
        <action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
    </intent-filter>
</service>

<!-- 手动添加App Center Push的组件,设置更高优先级确保被触发 -->
<receiver android:name="com.microsoft.appcenter.push.PushReceiver" 
          android:permission="com.google.android.c2dm.permission.SEND">
    <intent-filter android:priority="100">
        <action android:name="com.google.android.c2dm.intent.REGISTRATION" />
        <action android:name="com.google.android.c2dm.intent.RECEIVE" />
        <category android:name="se.crossplatform.parkeraapp" />
    </intent-filter>
</receiver>
<service android:name="com.microsoft.appcenter.push.TokenService">
    <intent-filter android:priority="100">
        <action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
    </intent-filter>
</service>

核心是给App Center的组件设置更高的优先级(android:priority="100"),这样系统会优先处理App Center的推送事件,同时Firebase的组件依然能正常支持Google登录功能。

2. 验证google-services插件的版本兼容性

确保android/build.gradle中引入的google-services插件版本与Firebase、App Center依赖兼容:

// 项目根目录的build.gradle
buildscript {
    dependencies {
        // 建议使用与项目依赖匹配的稳定版本
        classpath 'com.google.gms:google-services:4.3.15'
    }
}

// app模块的build.gradle
apply plugin: 'com.google.gms.google-services'

3. 清理缓存并重建项目

完成配置后,执行以下命令清理构建缓存并重新编译项目,确保所有配置生效:

cd android
./gradlew clean
cd ..
npx react-native run-android

原理说明

com.google.gms.google-services插件会自动扫描项目中的Firebase依赖并生成Manifest配置,但它不会考虑第三方推送服务(比如App Center Push)的需求。通过手动添加App Center的组件并设置更高优先级,我们可以让系统同时处理两个模块的Intent事件,既不影响Google登录功能,也能让App Center Push在后台正常接收通知。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.29 08:51:19