Closed nabilfreeman closed 2 years ago
I managed to get things mostly working without much stress. Autolinking does work so it's not necessary to do any gradle steps apart from the intercom-android
docs. Pretty cool.
I haven't tested push notifications yet.
I want able to build when trying to use intercom-sdk:6. @nabilfreeman what did you have to change to get it to build properly?
What build error are you getting @Vitiell0 ? As far as I recall it just worked out of the box. This is the first native module I implemented after rebuilding the app on a RN 61 platform.
Hard for me to tell you my config now as I've added tons of other bits to the build 🙈
To get react-native-intercom
working with the newest React Native Firebase (there is an example for this in the docs...
The change is quite simple to be honest, RNFirebaseMessagingService
has changed to ReactNativeFirebaseMessagingService
. That's it. Also, the original implementation was missing something for the Intercom push token that also needs to be present.
Feel free to remove the below logs, I found them really helpful.
PushNotificationService.java (make sure the name matches in AndroidManifest.xml
)
package com.your.package.name.here;
import io.intercom.android.sdk.push.IntercomPushClient;
import io.invertase.firebase.messaging.ReactNativeFirebaseMessagingService;
import com.google.firebase.messaging.RemoteMessage;
import android.util.Log;
import java.util.Map;
public class PushNotificationService extends ReactNativeFirebaseMessagingService {
private static final String TAG = "PushNotificationService";
private final IntercomPushClient intercomPushClient = new IntercomPushClient();
@Override
public void onNewToken(String refreshedToken) {
intercomPushClient.sendTokenToIntercom(getApplication(), refreshedToken);
super.onNewToken(refreshedToken);
}
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
Map message = remoteMessage.getData();
Log.d(TAG, "Hi I received a push message: " + message.toString());
if (intercomPushClient.isIntercomPush(message)) {
Log.d(TAG, "The message is from Intercom.");
intercomPushClient.handlePush(getApplication(), message);
} else {
Log.d(TAG, "The message is from Firebase.");
super.onMessageReceived(remoteMessage);
}
}
}
Thanks @nabilfreeman, the implementation you mentioned works with react-native-firebase 6 (the reworked version).
I added this to the AndroidManifest.xml
<activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
<service android:name=".PushNotificationService"
android:enabled="true"
android:exported="true" >
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
For any newcomers
This should definitely have a section on README.md
Intercom.addEventListener(Intercom.Notifications.UNREAD_COUNT, callback);
return () => {
Intercom.removeEventListener(
Intercom.Notifications.UNREAD_COUNT,
callback,
);
};
})
the callback doesn't get called even when there are unread messages until you call Intercom.displayMessenger
for the first time, after that it works fine.
This is only happening for Android, iOS is working fine. Any ideas on how to fix this?
@nabilfreeman I am getting this error
error: package io.invertase.firebase.messaging does not exist
what am i lacking of? any idea?
Any luck on this?
hey @aibrahim3546 i got the same error. i added @react-native-firebase/app and @react-native-firebase/messaging to fix it.
@tingzhouu @aibrahim3546 Don't forget to remove implementation "com.google.firebase:firebase-messaging:20.+"
from your app build.gradle. Unless @react-native-firebase/app
and @react-native-firebase/messaging
cannot autolinked properly. I was stuck here.
Intercom 5 is due to be discontinued and will stop working in June 2020.
Users need to install Intercom 6:
https://github.com/intercom/intercom-android
Additionally the MainMessagingService example for combining Intercom pushes with
react-native-firebase
no longer works due to a major version change on that library.I'm currently integrating this library with all the newer stuff - will post in this issue the necessary changes and then we can hopefully update the docs!