Hi all, I’m using UIKit v2.2.2 with Android, and I’m trying to send push notifications, but it doesn’t work because my users don’t have a device token. The problem is that I have another external library that uses Firebase and Huawei push notifications. Right now, I’ve done the following steps:
Created FCM and HMS services and added in the manifest
Override onNewToken and called SendBird.registerPushTokenForCurrentUser
Override onMessageReceived and handled notifications.
Of course, I’ve already registered the server keys and placed services’ JSON file in the app.
I’m not using SendBirdPushHelper.registerPushHandler and I don’t know if it’s mandatory for push, could you help me to understand the proper way to implement that?
I think the issue is you use other library that uses Firebase and Huawei.
Our Chat SDK should handle all messages from Firebase and Huawei. Is it possible unregister other library? How do you implement other library?
Like Sendibird, the other library has some methods called in onNewToken and onMessageReceived also it has an init method called in App. But the problem is that I can’t obtain a device token for my users. I tried a workaround adding SendBirdPushHelper.registerPushHandler(FirebaseMessagingServiceHandler()) in App where FirebaseMessagingServiceHandler extends SendBirdPushHandler and now my users have token, but how can I do the same with Huawei?
I’m trying to not implement FCM and HMS services as you suggested, but the problem is still there I can’t obtain a token for the users, if you look the screenshot below, I can’t send a test push
The problem, it could be related to the other library because it uses FirebaseMessagingService and HmsMessageService too, for that I tried to create two services (FCM and HMS) to handle both logic of Sendbird and the other library. But it works only, as I said above, if I create a FirebaseMessagingServiceHandler that extends SendBirdPushHandler and register with registerPushHandle in App, and of course I can’t do the same for Huawei.
Do you have any idea how to fix that? Sorry it seems a tough question, thank you for your time.
Yes, I had registered the server keys, in fact with FirebaseMessagingServiceHandler workaround it works normally, and I have users with token who can receive chat messages.
Did you implement registerPushToken method?
Yes, I created a FirebaseMessagingService, added in the manifest that implements registerPushTokenForCurrentUser
class FirebaseMessagingService : FirebaseMessagingService() {
override fun onNewToken(token: String) {
if (TextUtils.isEmpty(token)) {
return
}
SendBird.registerPushTokenForCurrentUser(token) { pushTokenRegistrationStatus, error ->
if (error != null) {
Timber.e(error)
}
if (pushTokenRegistrationStatus == PushTokenRegistrationStatus.PENDING) {
// A token registration is pending.
// Retry the registration after a connection has been successfully established.
}
}
}
override fun onMessageReceived(remoteMessage: RemoteMessage) { ... }
}
You implement both FirebaseMessagingServiceHandler that extends SendBirdPushHandler and FirebaseMessagingService that extends FirebaseMessagingService.
You can receive token from FirebaseMessagingService that extends FirebaseMessagingService. However, registerPushTokenForCurrentUser doesn’t work well. Right?
If above information is right, Could you give me a error log for registerPushTokenForCurrentUser?
I found the problem, in my implementation, SendBirdUIKit.init() isn’t called at the startup because I need some information from our backend to populate UserInfo. So, when I receive the token from FirebaseMessagingService that extends FirebaseMessagingService I can’t invoke successfully registerPushTokenForCurrentUser because SendBirdUIKit isn’t initialize. I’ve implemented the following:
Removed FirebaseMessagingServiceHandler that extends SendBirdPushHandler
When user info are available called SendBirdUIKit.init()
In onInitSucceed of InitResultHandler called SendBirdUIKit.connect
Retrieved FCM or HMS push token
Called registerPushTokenForCurrentUser
With that, I have users with push token that receive notifications. But now I have another issue, I don’t receive push when app is in foreground, should I call FirebaseMessagingServiceHandler with registerPushHandler inside SendBirdUIKit.connect? I already selected Send to devices both offline and online option.
In the Step4, You should use SendBirdPushHelper.registerPushHandler() with the class inheriting SendBirdPushHandler. SendBirdPushHandlerhasalwaysReceiveMessage(): Booleanmethod. You should override this method andreturn true` (default is false). Then, you can receive push notification foreground.