Giter VIP home page Giter VIP logo

react-native-voip-push-notification's Introduction

React Native VoIP Push Notification

npm version npm downloads

React Native VoIP Push Notification - Currently iOS >= 8.0 only

RN Version

  • 1.1.0+ ( RN 40+ )
  • 2.0.0+ (RN 60+)

!!IMPORTANT NOTE!!

You should use this module with CallKit:

Now Apple forced us to invoke CallKit ASAP when we receive voip push on iOS 13 and later, so you should check react-native-callkeep as well.

Please read below links carefully:

https://developer.apple.com/documentation/pushkit/pkpushregistrydelegate/2875784-pushregistry

When linking against the iOS 13 SDK or later, your implementation of this method must report notifications of type voIP to the CallKit framework by calling the reportNewIncomingCall(with:update:completion:) method

On iOS 13.0 and later, if you fail to report a call to CallKit, the system will terminate your app.

Repeatedly failing to report calls may cause the system to stop delivering any more VoIP push notifications to your app.

If you want to initiate a VoIP call without using CallKit, register for push notifications using the UserNotifications framework instead of PushKit. For more information, see UserNotifications.

Issue introduced in this change:

When received VoipPush, we should present CallKit ASAP even before RN instance initialization.

This breaks especially if you handled almost call behavior at js side, for example:
Do-Not-Disturb / check if Ghost-Call / using some sip libs to register or waiting invite...etc.

Staff from Apple gives some advisions for these issues in the below discussion: https://forums.developer.apple.com/thread/117939

You may need to change your server for APN voip push:

Especially apns-push-type value should be 'voip' for iOS 13
And be aware of apns-expirationvalue, adjust according to your call logics

https://developer.apple.com/documentation/usernotifications/setting_up_a_remote_notification_server/sending_notification_requests_to_apns

About Silent Push ( Background Push ):

VoIP pushes were intended to specifically support incoming call notifications and nothing else.

If you were using voip push to do things other than nootify incoming call, such as: cancel call / background updates...etc, You should change to use Notification Service Extension, it contains different kind of pushs.

To useBackground Push to Pushing Background Updates to Your App, You should:

  1. Make sure you enabled Xcode -> Signing & Capabilities -> Background Modes -> Remote Notifications enabled
  2. When sending background push from your APN back-end, the push header / payload should set:
    • content-available = 1
    • apns-push-type = 'background'
    • apns-priority = 5

Installation

npm install --save react-native-voip-push-notification
# --- if using pod
cd ios/ && pod install

The iOS version should be >= 8.0 since we are using PushKit.

Enable VoIP Push Notification and Get VoIP Certificate

Please refer to VoIP Best Practices.

Make sure you enabled the folowing in Xcode -> Signing & Capabilities:

  • Background Modes -> Voice over IP enabled
  • +Capability -> Push Notifications

AppDelegate.m Modification

...

#import <PushKit/PushKit.h>                    /* <------ add this line */
#import "RNVoipPushNotificationManager.h"      /* <------ add this line */

...

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
  RCTBridge *bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions];
  


  // ===== (THIS IS OPTIONAL BUT RECOMMENDED) =====
  // --- register VoipPushNotification here ASAP rather than in JS. Doing this from the JS side may be too slow for some use cases
  // --- see: https://github.com/react-native-webrtc/react-native-voip-push-notification/issues/59#issuecomment-691685841
  [RNVoipPushNotificationManager voipRegistration];
  // ===== (THIS IS OPTIONAL BUT RECOMMENDED) =====



  RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:bridge moduleName:@"AppName" 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.
}

// --- Handle incoming pushes
- (void)pushRegistry:(PKPushRegistry *)registry didReceiveIncomingPushWithPayload:(PKPushPayload *)payload forType:(PKPushType)type withCompletionHandler:(void (^)(void))completion {
  

  // --- NOTE: apple forced us to invoke callkit ASAP when we receive voip push
  // --- see: react-native-callkeep

  // --- Retrieve information from your voip push payload
  NSString *uuid = payload.dictionaryPayload[@"uuid"];
  NSString *callerName = [NSString stringWithFormat:@"%@ (Connecting...)", payload.dictionaryPayload[@"callerName"]];
  NSString *handle = payload.dictionaryPayload[@"handle"];

  // --- this is optional, only required if you want to call `completion()` on the js side
  [RNVoipPushNotificationManager addCompletionHandler:uuid completionHandler:completion];

  // --- Process the received push
  [RNVoipPushNotificationManager didReceiveIncomingPushWithPayload:payload forType:(NSString *)type];

  // --- You should make sure to report to callkit BEFORE execute `completion()`
  [RNCallKeep reportNewIncomingCall:uuid handle:handle handleType:@"generic" hasVideo:false localizedCallerName:callerName fromPushKit: YES payload:nil];
  
  // --- You don't need to call it if you stored `completion()` and will call it on the js side.
  completion();
}
...

@end

Linking:

On RN60+, auto linking with pod file should work.

Linking Manually

Add PushKit Framework:

  • In your Xcode project, select Build Phases --> Link Binary With Libraries
  • Add PushKit.framework

Add RNVoipPushNotification:

Option 1: Use rnpm

rnpm link react-native-voip-push-notification

Note: If you're using rnpm link make sure the Header Search Paths is recursive. (In step 3 of manually linking)

Option 2: Manually

  1. Drag node_modules/react-native-voip-push-notification/ios/RNVoipPushNotification.xcodeproj under <your_xcode_project>/Libraries
  2. Select <your_xcode_project> --> Build Phases --> Link Binary With Libraries - Drag Libraries/RNVoipPushNotification.xcodeproj/Products/libRNVoipPushNotification.a to Link Binary With Libraries
  3. Select <your_xcode_project> --> Build Settings - In Header Search Paths, add $(SRCROOT)/../node_modules/react-native-voip-push-notification/ios/RNVoipPushNotification with recursive

API and Usage:

Native API:

Voip Push is time sensitive, these native API mainly used in AppDelegate.m, especially before JS bridge is up. This usually

  • (void)voipRegistration --- register delegate for PushKit if you like to register in AppDelegate.m ASAP instead JS side ( too late for some use cases )
  • (void)didUpdatePushCredentials:(PKPushCredentials *)credentials forType:(NSString *)type --- call this api to fire 'register' event to JS
  • (void)didReceiveIncomingPushWithPayload:(PKPushPayload *)payload forType:(NSString *)type --- call this api to fire 'notification' event to JS
  • (void)addCompletionHandler:(NSString *)uuid completionHandler:(RNVoipPushNotificationCompletion)completionHandler --- add completionHandler to RNVoipPush module
  • (void)removeCompletionHandler:(NSString *)uuid --- remove completionHandler to RNVoipPush module

JS API:

  • registerVoipToken() --- JS method to register PushKit delegate
  • onVoipNotificationCompleted(notification.uuid) --- JS mehtod to tell PushKit we have handled received voip push

Events:

  • 'register' --- fired when PushKit give us the latest token
  • 'notification' --- fired when received voip push notification
  • 'didLoadWithEvents' --- fired when there are not-fired events been cached before js bridge is up
...

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

...

class MyComponent extends React.Component {

...

    // --- anywhere which is most comfortable and appropriate for you,
    // --- usually ASAP, ex: in your app.js or at some global scope.
    componentDidMount() {

        // --- NOTE: You still need to subscribe / handle the rest events as usuall.
        // --- This is just a helper whcih cache and propagate early fired events if and only if for
        // --- "the native events which DID fire BEFORE js bridge is initialed",
        // --- it does NOT mean this will have events each time when the app reopened.


        // ===== Step 1: subscribe `register` event =====
        // --- this.onVoipPushNotificationRegistered
        VoipPushNotification.addEventListener('register', (token) => {
            // --- send token to your apn provider server
        });

        // ===== Step 2: subscribe `notification` event =====
        // --- this.onVoipPushNotificationiReceived
        VoipPushNotification.addEventListener('notification', (notification) => {
            // --- when receive remote voip push, register your VoIP client, show local notification ... etc
            this.doSomething();
          
            // --- optionally, if you `addCompletionHandler` from the native side, once you have done the js jobs to initiate a call, call `completion()`
            VoipPushNotification.onVoipNotificationCompleted(notification.uuid);
        });

        // ===== Step 3: subscribe `didLoadWithEvents` event =====
        VoipPushNotification.addEventListener('didLoadWithEvents', (events) => {
            // --- this will fire when there are events occured before js bridge initialized
            // --- use this event to execute your event handler manually by event type

            if (!events || !Array.isArray(events) || events.length < 1) {
                return;
            }
            for (let voipPushEvent of events) {
                let { name, data } = voipPushEvent;
                if (name === VoipPushNotification.RNVoipPushRemoteNotificationsRegisteredEvent) {
                    this.onVoipPushNotificationRegistered(data);
                } else if (name === VoipPushNotification.RNVoipPushRemoteNotificationReceivedEvent) {
                    this.onVoipPushNotificationiReceived(data);
                }
            }
        });

        // ===== Step 4: register =====
        // --- it will be no-op if you have subscribed before (like in native side)
        // --- but will fire `register` event if we have latest cahced voip token ( it may be empty if no token at all )
        VoipPushNotification.registerVoipToken(); // --- register token
    }

    // --- unsubscribe event listeners
    componentWillUnmount() {
        VoipPushNotification.removeEventListener('didLoadWithEvents');
        VoipPushNotification.removeEventListener('register');
        VoipPushNotification.removeEventListener('notification');
    }
...
}

Original Author:

ianlin

License

ISC License (functionality equivalent to MIT License)

react-native-voip-push-notification's People

Contributors

abhishekvel avatar datso avatar davidperrenoud avatar dayze avatar ianlin avatar kylekurz avatar nsimonfr avatar r0b0t3d avatar raeesbhatti avatar ramijarrar avatar ricsam avatar rinordreshaj avatar romick2005 avatar stevengolemme avatar wandersonsousa avatar zxcpoiu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

react-native-voip-push-notification's Issues

Support for iOS 11+

I ve used this module for voip PN. All is good with iOS 9 and iOS 10, but on iOS 11 I can't receive voip PN also can't see voip token. How I can resolve this ?

app killed and screen locked

If app killed and screen locked [RNCallKeep][reportNewIncomingCall] doesn't open call screen.
Maybe You know how can I fix it?
ios: 13
in logs:

17:35:25.630074+0500 appname [RNVoipPushNotificationManager] constantsToExport currentState = background
17:35:28.160530+0500 appname RNInCallManager.init(): initialized
17:35:28.162852+0500 appname RNInCallManager._checkRecordPermission(): recordPermission=granted
17:35:28.166609+0500 appname RNInCallManager._checkCameraPermission(): using iOS7 api. cameraPermission=undetermined
17:35:28.289386+0500 appname [RNCallKeep][setup] options = {
appName = appname;
maximumCallGroups = 1;
supportsVideo = 0;
}
17:35:28.290937+0500 appname [RNCallKeep][getProviderConfiguration]
7:35:29.664081+0500 onlinepbx [react-native-permissions] ios.permission.MICROPHONE permission checked: granted
17:35:29.664110+0500 appname [RNVoipPushNotificationManager] voipRegistration
17:35:29.666877+0500 appname [RNCallKeep][reportNewIncomingCall] uuidString = 2452d430-bfca-4068-9cda-3d98f85ef878
17:35:29.667721+0500 appname [RNVoipPushNotificationManager] didReceiveIncomingPushWithPayload payload.dictionaryPayload = {
aps = {
alert = "call";
};
"caller_id_name" = 04391076;
handle = 04391076;
type = call;
uuid = "2452d430-bfca-4068-9cda-3d98f85ef878";
}, type = PKPushTypeVoIP
17:35:29.667749+0500 appname [RNVoipPushNotificationManager] handleRemoteNotificationReceived notification.userInfo = {
aps = {
alert = "call";
};
"caller_id_name" = 04391076;
handle = 04391076;
type = call;
uuid = "2452d430-bfca-4068-9cda-3d98f85ef878";
}

should make registerUserNotification optional

Hi, I think it would be great if you can make registerUserNotification as optional.

  1. Voip registration is not required to request notification permission.
  2. I am working on a project using react-native-firebase. That's mean I already registered for user notification. So I do not want to override my settings when setting up voip push.
  3. For ios 10 and above, [app registerUserNotificationSettings:notificationSettings] is deprecated. Use UserNotifications Framework's [UNUserNotificationCenter requestAuthorizationWithOptions:completionHandler:] and [UNUserNotificationCenter setNotificationCategories:] instead

Can't register completion handler in 2.1.0

When I try to register the completion handler I continue to get the following error

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+[RNVoipPushNotificationManager addCompletionHandler:completionHandler:]: unrecognized selector sent to class 0x102e4fcb8'

If i clikc on the function

[RNVoipPushNotificationManager addCompletionHandler:uuid completionHandler:completion];
I can see it exists.. I'm not sure what is happening. Any ideas?

Local Notification event listener is not logging any response

I'm working with iOS for VoIP notification and I've used react-native-voip-push-notification to handle my VoIP notification.

I'm able to trigger localNotification using the following code:

VoipPushNotification.addEventListener('notification', (notification) => {
        console.log('Notification:::', notification)
        VoipPushNotification.presentLocalNotification({
          alertBody: notification.getMessage()
        });
      });

but local Notification listener is not logging out any notifications:

VoipPushNotification.addEventListener('localNotification', (notification) => {
      // --- when user click local push
     console.log('Local Notification:::', notification)
    });

I've enabled push notification, Background mode (VoIP notification, Background fetch, and Remote notification) from xCode capabilities. I'm using RN0.59.10. Is there something I'm missing?

Thanks in advance
#30

didReceiveIncomingPushWithPayload not called in background/terminated

Everything works fine when app is running in foreground, method gets called and call screen shows. If I minimize the app though nothing gets called and nothing gets logged even. I have read over the readme a million times and followed every step.

Read this:
https://developer.apple.com/library/ios/documentation/Performance/Conceptual/EnergyGuide-iOS/OptimizeVoIP.html

Added this:
Background Modes -> Voice over IP

Any thoughts? Running iOS 13.4.1 on iPhone XR w/ RN 0.61.5

doesn't play custom sound

i tried .aiff, .mp3 format and placed my audio in resource/
and setting the audio name to soundName presentLocalNotification({soundName: 'azan_1.mp3'}),
but it still playing the default sound
can anyone give clear instruction how to set custom sound when notification arrive as there is no detail provide in package instruction

VoIP token is different from PushNotificationIOS token?

I'm trying to get VoIP notification using RN-VoIP-PN library so I've generated my VoIP token using following method:

VoipPushNotification.addEventListener('register', token => {
   console.log('VOIP TOKEN: ', token)
})

but my VoIP token was getting rejected by APN server saying that it's an invalid token. After seeing this I've tried using PushNotificationIOS for token and generated a token using the following code:

 PushNotificationIOS.addEventListener('notification', (token)=>{
        console.log('PushNotificationIOS token: ', token)
      })

and surprisingly this token was different from VoipPushNotification generated token and my APN server accepted this token.
There are multiple questions that I want to clarify

  1. Why both tokens are different even VoipPushNotification used PushNotificationIOS to generate there token?
  2. What's the difference between VoIP token and normal token? Can I use a normal token using the second method only?

Thanks in advance

Notification event listener is not logging any response

I'm working with iOS for VoIP notification and I've used react-native-callkit and react-native-voip-push-notification to handle my VoIP calls.

I'm able to trigger localNotification using the following code:

VoipPushNotification.presentLocalNotification({alertBody: "Local Notification Test"})

but my localNotification listener is not logging out any notifications (my app is on):

VoipPushNotification.addEventListener('localNotification', notification => {
      console.log('localnotification notify : ', notification)
    });

I've enabled push notification, Background mode (VoIP notification, Background fetch, and Remote notification) from x-code capabilities. I'm using RN0.58. Is something I'm missing?

Thanks in advance

'React/RCTBridgeModule.h' file not found when building project

Followed the install instructions per the documentation, and Xcode yields the following error when building:

'React/RCTBridgeModule.h' file not found

from the file 'RNVoipPushNotificationManager.m'.

Any guidance as to why this might be happening would be greatly appreciated!

Doesn't wake up on background

First of all thank you for package :)

My app can receive push notifications when phone screen is on. (app is closed also)

But if I turn off the screen wait like 10-15 seconds I can't get the PN. Is that an expected behavior? I guess not because I can get calls from whatsapp even (whatsapp is closed + screen is off)

Any ideas how to solve this?

I am running my app on testflight.

question

Thanks for this project, looking forward to giving it a ago.

I'm currently using regular push notifications but am finding them to be quite unreliable, especially the silent type that interact with my app and deliver some data, hence looking at voip notifications now. My question is, are VOIP messages different in any way from "normal" apple push notifications?

didReceiveIncomingPushWithPayload not called in debug mode

I am using OneSignal to send push notifications.

When I build my app for release mode, notifications arrive just fine. But when building for debug, the didReceiveIncomingPushWithPayload is never called and the notification is ignored. Although on OneSignal it says the notification was delivered.

registerVoipToken() is not a function

i try to install and run VoipPushNotification.registerVoipToken() so i got registerVoipToken() is not a function but VoipPushNotification.requestPermissions() work perfectly.

RN 0.59.10

question - configuration action buttons

Whats the correct syntax to use when configuring action buttons?
i know we have a method notification.getMessage() to retrieve the alertBody, but is there a method to retrieve action buttons?

This is what im doing:
VoipPushNotification.presentLocalNotification({
alertBody: notification.getMessage(),
alertAction: 'Accept',
applicationIconBadgeNumber: 1,
category: 'incoming_call',
});

But still, no action button is displayed and there is no badge number.

Custom sound notification

I'm not able to use push notifications with custom sounds.
I've added the caf file in my app resource bundle, which is also included in the copy bundle resources.

The soundname in my apn is exactly the same as provided in the resource bundle.

Any idea what i could do wrong? or is there any tutorial to follow which explains how to install a custom sound for notifications.

[iOS][2.0.0] Not awake closed app when received voip call.

We use voip-push-notification & react-native-callkeep on iOS to awake app from background mode / closed state when received a voip call.

It work fine in background mode. But when app in closed state. Nothing happen, no notifcation, no automation awake app.

We met this issue from version 2.0.0 and react native 0.60.6. V1 and react-native 0.59 work fine.

any ones met the same issue with us? Can we resolve this problem?

Use of undeclared identifier 'pushRegistry'

Hello,

I got an error of use of "Use of undeclared identifier 'pushRegistry'" whenever i write below code. Please help me to find out from this.

react-native-voip-push-notification : 2.1.0

#import "AppDelegate.h"

#import <React/RCTBridge.h>
#import <React/RCTBundleURLProvider.h>
#import <React/RCTRootView.h>
#import <Firebase.h>
#import "RNSplashScreen.h"
#import "RNCallKeep.h"
#import <PushKit/PushKit.h>
#import "RNVoipPushNotificationManager.h"
#import "RNFirebaseNotifications.h"
#import "RNFirebaseMessaging.h"

#if DEBUG
#import <FlipperKit/FlipperClient.h>
#import <FlipperKitLayoutPlugin/FlipperKitLayoutPlugin.h>
#import <FlipperKitUserDefaultsPlugin/FKUserDefaultsPlugin.h>
#import <FlipperKitNetworkPlugin/FlipperKitNetworkPlugin.h>
#import <SKIOSNetworkPlugin/SKIOSNetworkAdapter.h>
#import <FlipperKitReactPlugin/FlipperKitReactPlugin.h>

static void InitializeFlipper(UIApplication *application) {
FlipperClient *client = [FlipperClient sharedClient];
SKDescriptorMapper *layoutDescriptorMapper = [[SKDescriptorMapper alloc] initWithDefaults];
[client addPlugin:[[FlipperKitLayoutPlugin alloc] initWithRootNode:application withDescriptorMapper:layoutDescriptorMapper]];
[client addPlugin:[[FKUserDefaultsPlugin alloc] initWithSuiteName:nil]];
[client addPlugin:[FlipperKitReactPlugin new]];
[client addPlugin:[[FlipperKitNetworkPlugin alloc] initWithNetworkAdapter:[SKIOSNetworkAdapter new]]];
[client start];
}
#endif

@implementation AppDelegate

  • (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {

    if ([FIRApp defaultApp] == nil) {
    [FIRApp configure];
    }

    /* 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];
      }

How to send voip push notification?

Hi there,

i'm trying to intregrate voip push notification with callkeep. and i'm sending data like this:

{
    "aps": {
        "alert": "Hello Push",
        "sound": "default"
    },
    "uuid": "12212",
    "callerName": "Samad",
    "handle": "Task",
    "extra": {}
}

but when my app recieve a push notification i got an exception in main.m file
Thread 1: Exception: "-[CXProvider reportNewIncomingCallWithUUID:update:completion:]: parameter 'UUID' cannot be nil"

In AppDelegate.m
image

this is what i got from notification listner:
image

can anyone tell me what i'm doing wrong?

"react-native": "0.63.1",
"react-native-callkeep": "^3.1.1",
"react-native-voip-push-notification": "^2.1.0",

Notification not received after app killed

I have implemented this library with the RNCallKit library and nearly every time a notification is sent to the device, the notification is received and Call Kit does it's magic. However, there have been instances where after the app launches I kill the app, lock the device and let it go to sleep, then send a notification again. The notification is not received. If I simply wake the device (not unlock it, just let the screen light up), then the notification comes through and CallKit works. As far as I can tell, the didReceiveIncomingPushWithPayload in AppDelegate.m is not called. The notification is of type VoIP. Has anyone figured this out?

Event listeners aren't working

Nothing is logged when we do

    VoipPushNotification.addEventListener('localNotification', (notification) => {
     console.log(notification)
    })
      VoipPushNotification.presentLocalNotification({
          alertBody: "hello! "
      });

Also, register event is never triggered.

VoipPushNotification.addEventListener('register', (token) => {
      // send token to your apn provider server
 });

Please check

register event not firing if debugger is off

Hi @ianlin ,

First, Thanks for this Library!

Im having issue when debugger is ON, this is not firing, Im not getting the device token.

  componentWillMount () {
    VoipPushNotification.addEventListener('register', this._onRegister)
  }

  componentWillUnmount () {
    VoipPushNotification.removeEventListener('register', this._onRegister)
  }

  _onRegister(token) {
    console.tron.log({ token })
    this.setState({
      pushId: token
    })
  }

Else if debugger is ON the token is there:

screen shot 2017-06-07 at 2 15 57 pm

Though as I check my xcode console i'm seeing my token is registered.

screen shot 2017-06-07 at 2 14 38 pm

Receiving the notification even the debugger is OFF works as expected.

Cheers!

iOS 13 Support

iOS seems to change how VOIP Push notifications have to be handled. Apparently the app now has to almost immediately (as in basically first thing after notification) start the call notification, otherwise it won't respond.

Not sure if this package needs to be updated or if RN needs changing. Please LMK if you want any logs and I will happily post them here.

unrecognized selector sent to instance

The app crashes when it gets to this line of code:
VoipPushNotification.registerVoipToken();

This is the error in the XCode console:

2020-04-30 19:20:49.552892-0400 myApp[265:6055] [RNVoipPushNotificationManager] voipRegistration
2020-04-30 19:20:49.633725-0400 myApp[265:6055] -[AppDelegate pushRegistry:didUpdatePushCredentials:forType:]: unrecognized selector sent to instance 0x283c83580
2020-04-30 19:20:49.634672-0400 myApp[265:6055] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[AppDelegate pushRegistry:didUpdatePushCredentials:forType:]: unrecognized selector sent to instance 0x283c83580'
*** First throw call stack:
(0x1bff0f180 0x1bf0e79f8 0x1bfe2b9bc 0x1ec728220 0x1bff149c8 0x1bff1665c 0x1e16ae0b8 0x1048776f4 0x104878c78 0x1048866fc 0x1bfea0b20 0x1bfe9ba58 0x1bfe9afb4 0x1c209c79c 0x1ec6fcc38 0x1009a0d34 0x1bf95e8e0)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)

Screen Shot 2020-04-30 at 7 02 01 PM

didReceiveIncomingPushWithPayload it's triggered only in foreground

didReceiveIncomingPushWithPayload() it's triggered only in foreground.

Here is my appdelegate

`/**

  • Copyright (c) Facebook, Inc. and its affiliates.
  • This source code is licensed under the MIT license found in the
  • LICENSE file in the root directory of this source tree.
    */

#import "AppDelegate.h"

#import <React/RCTBridge.h>
#import <React/RCTBundleURLProvider.h>
#import <React/RCTRootView.h>
#import <Firebase.h>
#import "RNCallKeep.h"
#import <PushKit/PushKit.h> /* <------ add this line /
#import "RNVoipPushNotificationManager.h" /
<------ add this line */

@implementation AppDelegate

  • (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
    [FIRApp configure];
    RCTBridge *bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions];
    RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:bridge
    moduleName:@"ceva"
    initialProperties:nil];

    rootView.backgroundColor = [[UIColor alloc] initWithRed:1.0f green:1.0f blue:1.0f alpha:1];

    self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
    UIViewController *rootViewController = [UIViewController new];
    rootViewController.view = rootView;
    self.window.rootViewController = rootViewController;
    [self.window makeKeyAndVisible];
    return YES;
    }

  • (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
    {
    #if DEBUG
    return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil];
    #else
    return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
    #endif
    }

// Handle updated push credentials

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

}

// Handle incoming pushes

  • (void)pushRegistry:(PKPushRegistry *)registry didReceiveIncomingPushWithPayload:(PKPushPayload *)payload forType:(PKPushType)type withCompletionHandler:(void (^)(void))completion {
    // Process the received push
    [RNVoipPushNotificationManager didReceiveIncomingPushWithPayload:payload forType:(NSString *)type];

    NSString *uuid = [[[NSUUID UUID] UUIDString] lowercaseString];
    NSString *callerName = @"nume";
    NSString *handle = @"ext";
    NSLog(@"RNVoipPushNotificationManager ----- pushRegistry received");

    [RNCallKeep reportNewIncomingCall:uuid handle:handle handleType:@"generic" hasVideo:false localizedCallerName:callerName fromPushKit: YES];

    completion();
    }

  • (BOOL)application:(UIApplication *)application
    continueUserActivity:(NSUserActivity *)userActivity
    restorationHandler:(void(^)(NSArray * __nullable restorableObjects))restorationHandler
    {
    return [RNCallKeep application:application
    continueUserActivity:userActivity
    restorationHandler:restorationHandler];
    }

@EnD
`

Unable to removeEventListener

When trying to remove the event listener it's not removing so when mounting and unmount I;m getting doubled notifications

code

componentWillMount() {
    VoipPushNotification.addEventListener("notification", notification => {
      const data = notification.getData();
      this.notificationSwitch(data, notification);
    });
  }

  componentWillUnmount() {
    VoipPushNotification.removeEventListener("notification", () => {
      console.log("removed");
    });
  }

Also tried

componentWillMount() {
    VoipPushNotification.addEventListener("notification", notification => {
      const data = notification.getData();
      this.notificationSwitch(data, notification);
    });
  }

  componentWillUnmount() {
    VoipPushNotification.removeEventListener("notification");
  }

First notification is missed when app is killed

I'm encountering super weird bug. Basically, when I kill the app and send pushes, on the first push callKit is never shown, but it's shown on the following ones. I built the app in release mode, iOS version: 10.3.3.

Has anyone encountered this issue? Anyone solved it?

It might be related to issue #14 .

ts support

seems not yet support typescript?
Thanks

Cannot install pod after installing this dependency in React Native version>=0.60.0

Below is the error:-

[!] CocoaPods could not find compatible versions for pod "React/Core":
In Podfile:
RNVoipPushNotification (from ../node_modules/react-native-voip-push-notification) was resolved to 1.1.4, which depends on
React/Core

None of your spec sources contain a spec satisfying the dependency: React/Core.

You have either:

  • out-of-date source repos which you can update with pod repo update or with pod install --repo-update.
  • mistyped the name or version.
  • not added the source repo that hosts the Podspec to your Podfile.

Note: as of CocoaPods 1.0, pod repo update does not happen on pod install by default.

If anyone found this error then open node modules and navigate to react-native-voip-push-notification and open podspec file and change s.dependency 'React/Core' to s.dependency 'React-Core'.

But my request is to update this asap as i have waste my 8 hrs on this.

example

I am new to the IOS react land. I have react-native-push-notifications work but am trying to add voip. Is there a simple example available somewhere? My main question right now is what Add PushKit delegate method means in the appDelegate.m.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{

...

/* Add PushKit delegate method */

Can't show callkeep then app killed ios 13.4

Someone can show how to call CallKeep in ios 13.4 then the application was killed?
"react-native": "0.61.5",
"react-native-callkeep": "3.0.10",
"react-native-voip-push-notification": "^2.0.0",
- (void)pushRegistry:(PKPushRegistry *)registry didReceiveIncomingPushWithPayload:(PKPushPayload *)payload forType:(PKPushType)type withCompletionHandler:(void (^)(void))completion { // --- Process the received push [RNVoipPushNotificationManager didReceiveIncomingPushWithPayload:payload forType:(NSString *)type]; // --- NOTE: apple forced us to invoke callkit ASAP when we receive voip push // --- see: react-native-callkeep // --- Retrieve information from your voip push payload NSString *uuid = payload.dictionaryPayload[@"uuid"]; NSString *callerName = [NSString stringWithFormat:@"%@ (Connecting...)", payload.dictionaryPayload[@"callerName"]]; NSString *handle = payload.dictionaryPayload[@"handle"]; NSDictionary *extra = [payload.dictionaryPayload valueForKeyPath:@"call.boxt.one"]; // --- You should make sure to report to callkit BEFORE execute completion()[RNCallKeep reportNewIncomingCall:uuid handle:handle handleType:@"generic" hasVideo:false localizedCallerName:callerName fromPushKit: YES]; completion(); }

Facing the Issue With Reject Call On IOS 13 In Background Mode As App Is Crashing

When I get An Incoming VOIP Notification on IOS devices when App Is in Background mode, App Is Crashed Every time When I Reject the Notification. But Works Fine On Accept Call.
And Working Fine On Foreground Mode For Both Accept and reject.

XCODE LOGS:
2020-02-13 12:12:19.305827-0500 555 Phone RN[3791:1852152] Apps receving VoIP pushes must post an incoming call (via CallKit or IncomingCallNotifications) in the same run loop as pushRegistry:didReceiveIncomingPushWithPayload:forType:[withCompletionHandler:] without delay.
2020-02-13 12:12:19.307019-0500 555 Phone RN[3791:1852152] *** Assertion failure in -[PKPushRegistry _terminateAppIfThereAreUnhandledVoIPPushes], /BuildRoot/Library/Caches/com.apple.xbs/Sources/PushKit/PushKit-37/PKPushRegistry.m:343
2020-02-13 12:12:19.307351-0500 555 Phone RN[3791:1852152] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Killing app because it never posted an incoming call to the system after receiving a PushKit VoIP push callback.'
*** First throw call stack:
(0x18463d80c 0x184365fa4 0x18453fc4c 0x1849756f4 0x19831ba5c 0x10241ebd8 0x10242d858 0x19831a9cc 0x10241d7fc 0x10241ebd8 0x10242cc34 0x1845bb3a8 0x1845b639c 0x1845b58a0 0x18e50d328 0x1886a6740 0x100646844 0x184440360)
libc++abi.dylib: terminating with uncaught exception of type NSException

Is there a way to see if a local notification has been opened?

I have the following code that triggers the local notification but need an event listener that listeners for when it's been opened / app opens from the notifications

VoipPushNotification.presentLocalNotification({
      alertBody: notification.getMessage()
});

Issue where notifications are received when app is killed but not when just in background

Currently listening on the "notification" event and it appears as though I don't get the notification when the app is running in the background (not closed) but if you close the app then it gets notifications absolutely fine.

Is there another event I should be listening for? or should I be setting up the appdelegate differently to whats in the readme?

Rejected from App Store

I think it might be worth having a note in the readme that Apple will reject apps using this method if you are only using it for push notifications. That is, you must’ve using voice over IP services if you enable the voip background mode, or your app will get rejected.

App crash on notification receive

When receive notification app get crash with following error.

libc++abi.dylib: terminating with uncaught exception of type NSException

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.