ConnectyCube / connectycube-reactnative-samples

Chat and Video Chat code samples for React Native, ConnectyCube
https://connectycube.com
Apache License 2.0
124 stars 111 forks source link

Firebase Cloud Messaging on iOS #215

Closed gwenoleR closed 3 years ago

gwenoleR commented 3 years ago

Hi there !

I'm working on an implementation of Video Call in my current app and i have a question concerning the Push Notifications.

I saw on the doc than to receive notifications on iOS I have to subscribe to APNS notifications. But in my app, I already have FCM using react-native-firebase, and I don't want to integrate another library to receive push directly from APNS.

It should by nice if on iOS we can subscribe to FCM, something like that:

const params = {
      notification_channel: 'fcm', // use FCM for android & iOS
      device: {
        platform: Platform.OS,
        udid: deviceId
      },
      push_token: {
        environment: 'development',
        client_identification_sequence: token,
        bundle_identifier: 'com.company.app',
      }
    }

    ConnectyCube.pushnotifications.subscriptions.create(params)

Or maybe I missed something on the doc ?

DaveLomber commented 3 years ago

It's totally fine to use 'react-native-firebase' here

Please refer to general push notifications guide https://developers.connectycube.com/reactnative/push-notifications

and also there is a tiny section regarding 'react-native-firebase' at the bottom https://developers.connectycube.com/reactnative/push-notifications?id=react-native-firebase-lib

DaveLomber commented 3 years ago

So basically you have to use firebase.messaging().getAPNSToken() for iOS as a token

DaveLomber commented 3 years ago

And also please use notification_channel: Platform.OS === 'ios' ? 'apns' : 'gcm',

For android you should pass gcm even if you use Firebase token

gwenoleR commented 3 years ago

Hum, this is what I thought in the first place, but when I tried it, it was not working :(

I can see in the dashboard the new device subscription on APNS, but when i try to send notifications I have this error "No one can receive the message"

gwenoleR commented 3 years ago

Here, the method to send the push. I remove the voip parameters because I not subscribe to APNS_VOIP

const payload = JSON.stringify({
      uuid: this.callSession.ID,
      callerName: currentUserName,
      handle: currentUserName,
      hasVideo: this.callSession.callType === 1 ? '1' : '0',
      ios_badge: 1,
      // ios_voip: 1,
    })

    const pushParameters = {
      notification_type: 'push',
      user: { ids: [ccUserId] }, // recipients.
      environment: 'development',
      message: ConnectyCube.pushnotifications.base64Encode(payload),
    }

    ConnectyCube.pushnotifications.events
      .create(pushParameters)
DaveLomber commented 3 years ago

Make sure you have same 'environment' value when create push subscription and when send an event

gwenoleR commented 3 years ago

Unfortunatly, I double check, but this the same environment value :(

image

DaveLomber commented 3 years ago

Ok this is fine

Then check also user id you send a push to

There not many cases where it can throw the mentioned error

Either you send to a wrong user( w/o push subscription) or environment is diff

Only these 2

gwenoleR commented 3 years ago

I also check this 2,

I tried to send a push notification to user 3754019 on development environment

image

And this user have an APNS subscription

Capture d’écran 2021-03-18 à 10 47 55

and this subscription is in development environment

image

DaveLomber commented 3 years ago

@gwenoleR we have checked the provided information and everything looks good - no reason for it to not to work

We are investigating the case more at your side

gwenoleR commented 3 years ago

Ok, thanks @DaveLomber

If you need any informations I would be glad to help

gwenoleR commented 3 years ago

Hey @DaveLomber, any news ?

DaveLomber commented 3 years ago

@gwenoleR I finally was able to get the root cause

In terms of push subscriptions, everything is ok, a user has a proper subscription

But

We checked an iOS push certificate which you uploaded to Admin Panel and it says it's for APNS VOIP only , not a universal one. That's why the request is failing.

Please generate a universal iOS push certificate, which will cover normals pushes (dev+prod) plus voip pushes.

The guide is a bit outdated https://developers.connectycube.com/ios/how-to-create-apns-certificate but it shows the flow re how to do it

gwenoleR commented 3 years ago

@DaveLomber, thanks for your help.

You're right, with the good certificate the notification is send without error on iOS. But still, the firebase library doesn't fire any received event from your notification, strange.

I use now apns_voip, it seems to work fine with the react-native-voip-push-notification library

DaveLomber commented 3 years ago

@gwenoleR Google Firebase does not support iOS VOIP by itself

Hence using a react-native-voip-push-notification library is a right way

gwenoleR commented 3 years ago

Yeah I know, but i was trying with the apns type. Anyway, I didn't look why it didn't works because it's better to use the Voip Push :)