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

not receiving notification and give error code 422 #289

Closed ParmarJigarr closed 1 year ago

ParmarJigarr commented 2 years ago

'Users with ids 5351459 do not have push notification subscriptions' when sending msg using react native

ccvlad commented 2 years ago

https://developers.connectycube.com/reactnative/push-notifications?id=subscribe-to-push-notifications

ParmarJigarr commented 2 years ago

Yes , i have already performed this steps still getting this error in catch block

ccvlad commented 2 years ago

Attach logs were you do request and get response on subscription. And logs with the error 422

ParmarJigarr commented 2 years ago

event_log_61fba775059aea0011c02462.json.zip I am able to create session sucessfully , chatting is also working fine , i can also see the push notification token in our admin panel but for some reason i am getting 401 in push notification JSON this issue is only facing in IOS side !

ParmarJigarr commented 2 years ago

This is event log of successfully send message event_log_6200adb8ebf9ca00184a7013.json.zip

ParmarJigarr commented 2 years ago

Any update ?

DaveLomber commented 2 years ago

@ParmarJigarr we brought a new push notifications library which addressed some issues https://github.com/ConnectyCube/connectycube-reactnative-samples/pull/296

Please read the details and provide a feedback/comments if any

arnofo commented 1 year ago

Hello @ParmarJigarr, did you ever fix this issue ?

I'm seeing the exact same error message in the event_log_xxx.json as you did. Thx.

ParmarJigarr commented 1 year ago

@arnofo No brother , i am not able to send and receive push notification with connectycube :( , so i had implement push notification by REST API . Thank You

DaveLomber commented 1 year ago

@arnofo could you let me know which issue you are having now

arnofo commented 1 year ago

Here is the log from your backend : event_log_63d2baf5669b24002fd6130a.zip

This issue i am seeing is only on IOS.

I am using notifee with remote notification support as the library for receiving notifications : https://notifee.app/react-native/docs/ios/remote-notification-support

I was having issues with your library when opening (press action) notifications (especially when the app was in the background).

Everything works fine on Android.

I am now trying to test it on IOS but the notification never seems to be pushed to phone.

I believe it is not sent by APNs to the phone. Probably because of the 401 seen in the event_log_xxx.json.

DaveLomber commented 1 year ago

@arnofo according to backend log, the notification is failed to delivery with error status code 401, so the APNS server failed to accept the push request by some reason.

401 generally means Unauthorised. There could be one main reason:

arnofo commented 1 year ago

Here it is :

Screenshot 2023-01-30 090439

Yes that was my understanding of the 401 as well but without a more precise error message, i am having a hard time finding what exactly goes wrong.

These kind of 401 mean that we cannot push to the APNs server or that the push message is rejected by the specific device targeted ?

DaveLomber commented 1 year ago

@arnofo one more question when you subscribe to pushes via 'create subscription' API, do you pass bundle_id or not? If yes, is it equal to bundle_id of you APNS certificate?

arnofo commented 1 year ago

No i do not pass bundle_id. I am going to try to debug again tomorrow, i will let you know if i find anything else.

DaveLomber commented 1 year ago

@arnofo another idea is that you use wrong device token when subscribe to push notifications. It should be around 64 chars. Could you show an example of your device token so we can compare?

Also, please provide a code snippet how you obtain device token via notifee lib. It might be you are using wrong method. Let's check together

arnofo commented 1 year ago

Hello @DaveLomber

You were right i was not getting the proper token for IOS. I misunderstood the full scope of how the push notifications worked with ConnectyCube. (i did not do the initial setup on the project i am working on)

Connectycube uses firebase to send Android push notifications and APNs directly for IOS push notifications.

In my code, i was getting a token from Firebase for both platform :

// Get the token from FCM
const token = await messaging().getToken();

I should have been using the package @react-native-community/push-notification-ios :

// Request permissions (required for iOS)
// requestPermissions will trigger registerForRemoteNotifications implicitly.
// register listener will get device token.
PushNotificationIOS.requestPermissions({
      alert: true,
      badge: true,
      sound: true,
});

PushNotificationIOS.addEventListener('register', (token) => {
      const token = token;
});

Then you use the token to create the subscription on Connectycube.

Few other clues that might help people that wanted to use notifee:

(I still have a few edge cases to handle but most of the solution is working now)

Thanks for the help @DaveLomber.

DaveLomber commented 1 year ago

@arnofo thanks for confirming it!

For someone who might use the notifee lib as well - we added a ref to this GitHub issue from documentation https://developers.connectycube.com/reactnative/push-notifications?id=notifee-lib

I will close the issue for now then, feel free to open another one for any other issues/questions