Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[expo 34]Android only: get duplicate push notification when use react-native-firebase with Expokit #5304

Closed
changLiuUNSW opened this issue Aug 13, 2019 · 10 comments
Labels

Comments

@changLiuUNSW
Copy link
Contributor

changLiuUNSW commented Aug 13, 2019

My app is ejected from expokit 34 and we installed react-native-firebase for push notification and analytics.
Currently we have an issue that for each push notification we get it twice in Android:
20190813_133844
I suspect expokit may have some code for the notification which is duplicated with react-native-firebase.
Is there any solution or workaround for now? This issue has blocked us from release, please help !

@changLiuUNSW
Copy link
Contributor Author

I know you guys are focusing on Bare Workflow currently but we cannot use it due to OTA feature. I really hope someone can help us with this issue ...

@changLiuUNSW changLiuUNSW changed the title [expo 34]get duplicate push notification when use react-native-firebase with Expokit [expo 34]Android only: get duplicate push notification when use react-native-firebase with Expokit Aug 13, 2019
@changLiuUNSW
Copy link
Contributor Author

changLiuUNSW commented Aug 13, 2019

After research, I think I found out the solution/workaround now.
in AndroidManifest.xml, we have to comment out (disable) the GCM-part as below

   <!-- GCM -->
    <receiver
      android:name="com.google.android.gms.gcm.GcmReceiver"
      android:exported="true"
      android:permission="com.google.android.c2dm.permission.SEND">
      <intent-filter>
        <action android:name="com.google.android.c2dm.intent.RECEIVE"/>
        <action android:name="com.google.android.c2dm.intent.REGISTRATION"/>

        <category android:name="com.prospa.mobile"/>
      </intent-filter>
    </receiver>

    <service
      android:name=".gcm.ExponentGcmListenerService"
      android:exported="false">
      <intent-filter>
        <action android:name="com.google.android.c2dm.intent.RECEIVE"/>
      </intent-filter>
    </service>
    <service
      android:name=".gcm.ExponentInstanceIDListenerService"
      android:exported="false">
      <intent-filter>
        <action android:name="com.google.android.gms.iid.InstanceID"/>
      </intent-filter>
    </service>
    <service
      android:name=".gcm.GcmRegistrationIntentService"
      android:exported="false">
    </service>

@changLiuUNSW
Copy link
Contributor Author

Not sure whether we should update document to add this step in.
https://docs.expo.io/versions/v34.0.0/guides/using-fcm/

@derekstavis
Copy link
Contributor

derekstavis commented Aug 13, 2019

Hey. I had the same issue. I debugged the entire codebase to understand what was going on here and I came to a final solution that doesn't involve changing anything on standalone apps (either built through Turtle or ExpoKit).

If you are sending the notification using FCM by yourself you can't send the "notification" key. You need to send data-only notifications. Make sure your body includes:

"notification": null,
"data": {
  "experienceId": "@username/project",
  "title": "Your title",
  "message": "Your body",
  "body": { "your": "JSON data" },
  "channelId": "default",
},

If your "notification" body is anything other than null, you'll receive duplicated notifications.

🚨 ⚠️ BEAR IN MIND THAT THIS IS A PRIVATE API AND EXPO MIGHT CHANGE IT AT ANYTIME WITHOUT PRIOR NOTICE. 🚨 ⚠️

@derekstavis
Copy link
Contributor

Please close this as a duplicate of #4450.

@changLiuUNSW
Copy link
Contributor Author

changLiuUNSW commented Aug 13, 2019

@derekstavis I do not think it is duplicate. My issue is related to GCM code above AndroidManifest.xml.
The solution has been documented in this thread.
https://forums.expo.io/t/solved-android-receive-data-from-a-fcm-push-notification-in-detached-app/12940/3

After detaching
in AndroidManifest.xml
comment (disable) the GCM-part
keep the FCM-part untouched

However in official doc, it miss the first step comment (disable) the GCM-part which causes duplicate push notification in my app

@changLiuUNSW
Copy link
Contributor Author

changLiuUNSW commented Aug 13, 2019

@derekstavis I can confirm that I can send "notification" body without duplicate notifications, maybe because I installed React-native-firebase in my app.

BTW I also comment out FCM section (below) in AndroidManifest.xml

    <!-- FCM -->
    <service
      android:name=".fcm.ExpoFcmMessagingService">
      <intent-filter>
        <action android:name="com.google.firebase.MESSAGING_EVENT"/>
      </intent-filter>
    </service>
    <meta-data
      android:name="com.google.firebase.messaging.default_notification_icon"
      android:resource="@drawable/shell_notification_icon" />
    <meta-data
      android:name="com.google.firebase.messaging.default_notification_color"
      android:resource="@color/iconBackground" />
    <service
      android:name=".fcm.FcmRegistrationIntentService"
      android:exported="false">
    </service>

Added React-native-firebase instead:

    <service android:name="io.invertase.firebase.messaging.RNFirebaseMessagingService">
      <intent-filter>
        <action android:name="com.google.firebase.MESSAGING_EVENT" />
      </intent-filter>
    </service>
    <meta-data
      android:name="com.google.firebase.messaging.default_notification_icon"
      android:resource="@drawable/shell_notification_icon" />
    <meta-data
      android:name="com.google.firebase.messaging.default_notification_color"
      android:resource="@color/iconBackground" />
    <service android:name="io.invertase.firebase.messaging.RNFirebaseBackgroundMessagingService" />
    <receiver android:name="io.invertase.firebase.notifications.RNFirebaseNotificationReceiver"/>
      <receiver android:enabled="true" android:exported="true"  android:name="io.invertase.firebase.notifications.RNFirebaseNotificationsRebootReceiver">
        <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>

@cruzach
Copy link
Contributor

cruzach commented Aug 14, 2019

@changLiuUNSW can you confirm that without the changes you are making to the manifest, the change suggested above regarding format for the notifications payload doesn't fix the issue?

@changLiuUNSW
Copy link
Contributor Author

@cruzach I do not have a change to test it, because my app is ejected and I do not use Expo to manage the push notification anymore.
Basically as I mentioned above, the root cause is the GCM code is conflict with FCM code.
For ejected app, if you are using FCM for Push Notifications, you need to remove GCM code in the manifest. I just created a PR to add this additional step.
#5308
However, I think this issue also exists in standalone app if you are using FCM for Push Notifications

@cruzach
Copy link
Contributor

cruzach commented Oct 15, 2019

Closed via #5308

@cruzach cruzach closed this as completed Oct 15, 2019
@lock lock bot added the outdated label Apr 15, 2020
@lock lock bot locked and limited conversation to collaborators Apr 15, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants