react-native-fcm android通知无法正常工作

时间:2018-06-06 12:31:10

标签: android firebase react-native google-cloud-messaging react-native-fcm

我第一次使用react-native-fcm并根据文档我已经完成了所有链接工作,并使用firebase控制台中的云消息传递选项卡发送通知。

发送通知后状态是完整的,对于IOS来说它的工作正常(获得通知)但是android什么都没有出现。 我正在使用mi设备进行测试 android N 这是我的 build.gradle 设置。

    compileSdkVersion 26
    buildToolsVersion "26.0.2"

    defaultConfig {
        applicationId "XXXXXX"
        minSdkVersion 21
        targetSdkVersion 26
        versionCode 39
        versionName "1.91"
        ndk {
            abiFilters "armeabi-v7a", "x86"
        }
    }

请帮助我,我正在寻找一个漫长但无法找到的解决方案。 提前谢谢!!!

  

在8/6/2018进行一些实验后进行编辑

我已经尝试了很多东西没有锻炼然后我已经创建了一个新的项目firebase并且反应原生。并且一切正在进行(获取通知)然后我开始检查我的旧项目文件和新文件,经过这么多实验,我发现问题是tools:node="replace"我已经添加了这个因为react-native-facebook-login(谷歌的一些解决方案我得到了一些错误。

现在请帮我解决这个Android代码如何编写它,因为我的假设是tools:node="replace"根据this reference覆盖我的fcm代码与Facebook登录一个。在点击应用图标后,我无法删除tools:node="replace"崩溃的应用。

<application
      tools:node="replace" <-- this is culprit
      android:name=".MainApplication"
      android:label="@string/app_name"
      android:icon="@mipmap/ic_launcher"
      android:allowBackup="false"
      android:theme="@style/AppTheme">
      <receiver android:name="com.evollu.react.fcm.FIRLocalMessagingPublisher"/>
      <receiver android:enabled="true" android:exported="true"  android:name="com.evollu.react.fcm.FIRSystemBootEventReceiver">
        <intent-filter>
          <action android:name="android.intent.action.BOOT_COMPLETED"/>
          <action android:name="android.intent.action.QUICKBOOT_POWERON"/>
          <action android:name="com.htc.intent.action.QUICKBOOT_POWERON"/>
          <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
      </receiver>
      <!-- <meta-data android:name="com.google.firebase.messaging.default_notification_icon" android:resource="@mipmap/icon"/> -->
      <service android:name="com.evollu.react.fcm.MessagingService" android:enabled="true" android:exported="true">
        <intent-filter>
          <action android:name="com.google.firebase.MESSAGING_EVENT"/>
        </intent-filter>
      </service>
      <service android:name="com.evollu.react.fcm.InstanceIdService" android:exported="false">
        <intent-filter>
          <action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
        </intent-filter>
      </service>
      <activity
        android:name=".MainActivity"
        android:label="@string/app_name"
        android:launchMode="singleTop"
        android:screenOrientation="portrait"
        android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
        android:windowSoftInputMode="adjustPan">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
      </activity>
      <activity android:screenOrientation="portrait" android:name="com.facebook.react.devsupport.DevSettingsActivity" />

      <!--add FacebookActivity-->
      <activity
        tools:replace="android:theme"
        android:screenOrientation="portrait"
        android:name="com.facebook.FacebookActivity"
        android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
        android:label="@string/app_name"
        android:theme="@android:style/Theme.Translucent.NoTitleBar"/>

      <!--add CustomTabActivity-->
      <activity
        android:screenOrientation="portrait"
        android:name="com.facebook.CustomTabActivity"
        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" />
            <data android:scheme="@string/fb_login_protocol_scheme" />
        </intent-filter>
      </activity>

      <!--reference your fb_app_id-->
      <meta-data
        android:name="com.facebook.sdk.ApplicationId"
        android:value="@string/fb_app_id"/>
      <meta-data android:name="com.bugsnag.android.API_KEY"
        android:value="xxxxxxxxxxxxxx"/>
    </application>

1 个答案:

答案 0 :(得分:1)

即使你发布了android / build.gradle甚至android / app / build.gradle的所有内容,我也想帮你说你应该使用react-native-firebase,因为react-native-fcm会不再接收新功能。

  

react-native-firebase引入了新的firebase消息传递和远程/本地通知功能。它与其他firebase功能很好地集成。我会建议新来的人来检查一下。

     

请注意,仍有一些高级功能正在进行中

     

在应用未运行时处理iOS远程通知   自定义iOS通知操作   对于现有的react-native-fcm用户   react-native-firebase现在可以执行react-native-fcm所能做的事情,因此并行构建相同的东西是浪费精力。

     

由于这些天我越来越忙,并且开始感到难以每天维护这个回购,而react-native-firebase有一个更大的团队/公司支持它,现有用户可能会考虑迁移到react-native-firebase。

     

我使用react-native-firebase作为迁移参考创建了一个示例项目

     

react-native-fcm仍将采用PR和错误修复,但可能不再有新的功能开发。

相关问题