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

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

support store `completion` for invoke later #52

Closed zxcpoiu closed 4 years ago

zxcpoiu commented 4 years ago

Motivation

From iOS 11+, we should use

(void)pushRegistry:(PKPushRegistry *)registry didReceiveIncomingPushWithPayload:(PKPushPayload *)payload forType:(PKPushType)type withCompletionHandler:(void (^)(void))completion

Apple asked us to call completion() when we've done the job.

I've observed that if we call completion() directly after reportCallkit on the native side in the same block of didReceiveIncomingPushWithPayload, since react native initialized asynchronously and we might have some works to do on the JS side to initiate a call, in this case, if we call completion() too early, it may cause our js job to stop executing. ( The system revoke the execution lock when we call completion() I guess. And seems different iOS version acts differently when call completion())

This may be useful to someone.

Usage:

https://github.com/react-native-webrtc/react-native-voip-push-notification/pull/52/commits/d519beed33bd7c15ac3db7a9fec7190da6a825ec

zxcpoiu commented 4 years ago

I'll leave it here for few days/weeks for feedback.

vinayr commented 4 years ago

Please merge this. Without this, it's a hit or miss. With this, JS bridge works 100% of the time. Tested on iPhone 6 (iOS 12.4.5)

tsugitta commented 4 years ago

by using this, is it possible to call reportNewIncomingCall from JS layer and then call completion() ?

zxcpoiu commented 4 years ago

@tsugitta

No, I don't think so. Apple says should invoke reportNewIncomingCall ASAP and in the same block of the function. We might have successfully to call reportNewIncomingCall on the js side, but it's risky, because no one knows what is the algorithm behind the scene of current ios version that determine when to kill your app.

dariomalfatti-centropaghe commented 2 years ago

When I call reportNewIncomingCall passing the completion handler to withCompletionHandler property, on js side, have I to call VoipPushNotification.onVoipNotificationCompleted(notification.uuid); to let iOS know that it's finished? Right after calling the reportNewIncomingCall method on the native site, my phone starts ringing but I'm still doing some jobs on js side, like registration. It's that right? I thought that only after I would call the completion method, It would starts the call flow. Thank you in advance if someone can clarify the logic behind it.