react-native-voip-push-notification: register event not working

I looked at all the solutions offered, I looked at the answers to those who shared this error before, but none of them worked. I have been working for 1 day and haven’t even once received a token. I’ve tried it on a few phones. It doesn’t work. Please help.

  RCTBridge *bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions];
  [RNVoipPushNotificationManager voipRegistration];
  RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:bridge
                                                   moduleName:@"Myapp"
                                            initialProperties:nil];
 /* Add PushKit delegate method */

// --- Handle updated push credentials
- (void)pushRegistry:(PKPushRegistry *)registry didUpdatePushCredentials:(PKPushCredentials *)credentials forType:(PKPushType)type {
  // Register VoIP push token (a property of PKPushCredentials) with server
  [RNVoipPushNotificationManager didUpdatePushCredentials:credentials forType:(NSString *)type];
}

- (void)pushRegistry:(PKPushRegistry *)registry didInvalidatePushTokenForType:(PKPushType)type
{
  // --- The system calls this method when a previously provided push token is no longer valid for use. No action is necessary on your part to reregister the push type. Instead, use this method to notify your server not to send push notifications using the matching push token.
}

import VoipPushNotification from 'react-native-voip-push-notification';

 VoipPushNotification.addEventListener('register', (token) => {
                console.log(token, "voip token");
 });

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 18 (8 by maintainers)

Most upvoted comments

94c19d0be742ce6ab01ea2545fb2a5518c1dcac3044f62ca666ae9cdb8b6eaba is this a true voip token?

When i try like this its work.

 VoipPushNotification.registerVoipToken();

            VoipPushNotification.addEventListener('register', (deviceToken) => {
                console.log(deviceToken, "voip token");
            });

Before i removed this from appdelegate.m

[RNVoipPushNotificationManager voipRegistration];

Let me try to explain. When is in background there is no react native app running so that means that no javascript is running. There are two ways to init events for voip: 1) From objective c 2) From js add listener. But in js case if app in backround register event is fired before app js part attach “register” is initialized. That is why it does not for you. Bu the way you can check that by sending voip notification when app is running it should work for you. But when it is not running (in background mode) you should listen cached register event on didLoadWithEvents and there you will find register event that was fired by native code before app javascript started. Can you please verify/check this statement?

Is it simulator?

Thanks @Romick2005 for the help.

@CMLCNL please try 3.1.0, now it fires register enevt with the latest cached token for you if you have register voip token on the native side and call registerVoipToken on JS side again.