react-native-webrtc / react-native-voip-push-notification

React Native VoIP Push Notification - Currently iOS only
ISC License
213 stars 83 forks source link

iOS 13 Support #36

Closed ajnozari closed 4 years ago

ajnozari commented 5 years ago

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.

ajnozari commented 5 years ago

Ok so I've been digging into it, and we need to "start" the call within

- (void)pushRegistry:(PKPushRegistry *)registry didReceiveIncomingPushWithPayload:(PKPushPayload *)payload forType:(NSString *)type { // Process the received push [RNVoipPushNotificationManager didReceiveIncomingPushWithPayload:payload forType:(NSString *)type]; }

you dispatch an event here

- (void)handleRemoteNotificationReceived:(NSNotification *)notification { NSLog(@"[RNVoipPushNotificationManager] handleRemoteNotificationReceived notification.userInfo = %@", notification.userInfo); [_bridge.eventDispatcher sendDeviceEventWithName:@"voipRemoteNotificationReceived" body:notification.userInfo]; }

but that's native code and I can't imagine that we can call callkeep here.

So my idea is instead to run the call start from callkeep within the listener for notification within the RNVoipPushNotification's contstructor through adding a callback. Not sure if this is the right direction to go though but apple is restricting how we handle voip notifications in iOS 13.

If I can I'll attempt to implement this and submit a PR for it. If anyone has another solution I'd love to hear it.

r0b0t3d commented 5 years ago

Hi @ajnozari As document said

optional func pushRegistry(_ registry: PKPushRegistry, 
didReceiveIncomingPushWith payload: PKPushPayload, 
                       for type: PKPushType, 
                completion: @escaping () -> Void)

On iOS 13.0 and later, incoming Voice over IP calls must be reported when they are received and before this method finishes execution

So I think we have to call displayIncomingCall (from RNCallKeep) directly.

I made some update here https://github.com/r0b0t3d/react-native-callkeep/commit/3bed1be7459f650968e34778d1b1893d8957e414

And call it inside AppDelegate.m

// Handle incoming pushes
- (void)pushRegistry:(PKPushRegistry *)registry didReceiveIncomingPushWithPayload:(PKPushPayload *)payload forType:(NSString *)type {
  // Process the received push
  NSLog(@"RNVoipPushNotificationManager pushRegistry received");
  // Add this line
  [[RNCallKeep sharedInstance] displayIncomingCall:@"110ec58a-a0f2-4ac4-8393-c866d813b8d1" handle:@"generic" handleType:@"" hasVideo:true localizedCallerName:@"Caller Name"];

  [RNVoipPushNotificationManager didReceiveIncomingPushWithPayload:payload forType:(NSString *)type];
}

How do you think?

ajnozari commented 5 years ago

I don’t see any outright issues. I’ll give it a test later. Had to pause things as we’re migrating to a new host.

Linoa65 commented 4 years ago

Hi everybody !

Some news about that ? What we need to change in our code to adapt it for iOS 13 ? There will be an update of the module to support IOS 13 ? What sort of changes implies IOS 13 about voip notification ?

Apple told us we had until April 2020 to make this changes to our app, but for react-native, I have actually no idea about what we need to do.

Thank you :) Florient

r0b0t3d commented 4 years ago

@Linoa65

OriAmir commented 4 years ago

@r0b0t3d @ianlin @Linoa65
This library is deprecated and will not get any update any more ( for example iOS 13 ) ? Or maybe(i wish!) someone will take care and stay this library a live and updated ? It's really good library! There is another alternative ? the only thing i see is this : https://documentation.onesignal.com/docs/voip-notifications but it's have just regular react native library and not voip react native library .

tnx!

zxcpoiu commented 4 years ago

@manuquentin @sboily

Will you be interested in keep this library working closely with callkeep?

Or is there someone willing to do this?

Linoa65 commented 4 years ago

Hello there,

I have not enough skills in IOS development to correctly update this library, but if needed I can help and try to maintain it with other developers. This library is simple and effective, all we need I react-native, and it is not needed to work with call kit (what I need to have to display my calls like I want).

Thanks ! :)

OriAmir commented 4 years ago

anyone gone to take care on this library ? it's really god one , the modifications is big ?

sboily commented 4 years ago

Hello, sorry we don't talk about that with @manuquentin but we don't really use it. @zxcpoiu you need to find a new maintainer for this lib?

Linoa65 commented 4 years ago

I don't understand what implied the new way to catch notification VOiP. Is at registering we need to modify things ? Because I heard that we need to immediately send notification to CallKit to handle the VOiP notification, but I need to use my own custom display for the call, is it possible ?

ajnozari commented 4 years ago

So with IOS 13 within the loop that listens for the incoming VOIP notification you have to complete the handling and tell the phone to display the call at that point. This happens in your appdelegate.m.

Call kit has extended themselves to handle this and can handle the voip.

OriAmir commented 4 years ago

@ajnozari how complicated is to change the library to support that ?

ajnozari commented 4 years ago

@ajnozari how complicated is to change the library to support that ?

So I made a temp fix before these packages were updated, and that took me maybe 15 minutes.

Now that these packages are properly updated, it’s probably a copy-paste from the readme with a moment spent to check and make sure your variable names in the payload matches the native code and you’re done.

This will require you to edit the AppDelegate.m (which you should have already done once if push notifications are implemented in your app). So you will have to probably make minor edits to native code (see above about variable names). However if you’ve gotten this far it’s not a complicated fix.

ajnozari commented 4 years ago

Closing as this has been fixed by recent updates.

OriAmir commented 4 years ago

@ajnozari Thanks, but I can't see your code or any pull request , did you update the library or something?

lonnylot commented 4 years ago

@ajnozari to be clear: was it fixed by an update to this package, an update to iOS, or https://github.com/react-native-webrtc/react-native-voip-push-notification/issues/36#issuecomment-510836436

danwhite-ipc commented 4 years ago

Adding the following to the didReceiveIncomingPushWithPayload always me to get the call notification when the app is in the background. Still cannot get it to work when the app has been killed.

    NSString *uuid = [[NSUUID UUID] UUIDString];
    [RNCallKeep reportNewIncomingCall:uuid handle:@"07...." handleType:@"number" hasVideo:NO localizedCallerName:@"CallersName" fromPushKit:YES];
yannickmodahgouez commented 4 years ago

Closing as this has been fixed by recent updates.

Which updates fixed this issue ?

ajnozari commented 4 years ago

I made a fix to my app delegate that called the CallKeep native code function for displaying the call screen. I triggered this within my appdelegate. In fact CallKeep has since updated their documentation to provide this fix. Their solution is cleaner and I have switched my temp fix to their changes.

I closed this issue since it was not an issue for this package to fix, as it still works properly for iOS 13, it just requires a different implementation.

ajnozari commented 4 years ago

Adding the following to the didReceiveIncomingPushWithPayload always me to get the call notification when the app is in the background. Still cannot get it to work when the app has been killed.

    NSString *uuid = [[NSUUID UUID] UUIDString];
    [RNCallKeep reportNewIncomingCall:uuid handle:@"07...." handleType:@"number" hasVideo:NO localizedCallerName:@"CallersName" fromPushKit:YES];

As a quick question have you tried pushing to TestFlight and using the non-sandbox url? I’ve noticed that background ringing doesn’t work reliably with the app in debug scheme/dev mode, and release doesn’t prompt for production device tokens until pushed.

However I’ve never had an issue with the app in TestFlight or production and receiving calls while killed. I really think it’s a limitation of the sandbox.