Taracque / ionic-plugin-callkit

Ionic/Cordova plugin for CallKit
36 stars 20 forks source link

"reportIncomingCall" not working inside setTimeout #10

Open VinceOPS opened 7 years ago

VinceOPS commented 7 years ago

Hi,

First, thanks for this plugin, it works beautifully :-).

Platform & versions cordova 6.5 cordova-ios 4.3.1 iOS 10.2+ iPhone 5

Issue Today I ran into my first problem: using iOS, I noticed that if I send my app to the background (simply by pushing the iphone "home" button), before an expected call to callKit.reportIncomingCall, then nothing happens when my iPhone is waiting on the iOS home screen (I'd like it to display the Incoming call screen). I thought about the app being in 'pause' state... However, I can see my logs (console.log shown in the Safari debugger) made while the app is in the background, meaning (I guess) that my javascript code is still running... As soon as I get back into my app, the call is immediatly reported (the CallKit screen appears, and the device vibrates).

Is there anything I did wrong here? In the device logs, I can see the following (at the expected time, yet nothing happens):

May 10 18:06:14 iPhone-Dev MyApp(CallKit)[369] : Provider <CXXPCProvider: 0x762abf0> was asked to report a new incoming call with UUID: 130...... (etc, truncated)

I added console logging from the beginning of my process up to callKit.reportIncomingCall(). I can see all logs up to this point. Yet the call screen never shows... (until I take the app back to the foreground).

I cannot reproduce the issue on Android (everything is working perfectly).

Thanks!

Taracque commented 7 years ago

You need something which starts the incoming call flow. In most cases this is a Voip Push message, which wakes your app. (You can see such an ionic plugin here: https://github.com/Taracque/cordova-plugin-voippush) Otherwise you will need a Background Task on iOS to wake your app.

VinceOPS commented 7 years ago

Hi @Taracque, thanks for your answer.

Yup, I plan to implement PushKit sooner or later, as I want my users to be able to answer a call even if the app has been paused or killed.

However, regarding my report, it seems that the fault was on the setTimeout wrapping the call of reportIncomingCall. I was doing a dummy-testing straight code like: 1- register 2- setTimeout(reportNewCall, 2500), with a delay of 2500ms in order to make sure that the plugin has been completely registered/initialized. If register call is made earlier, and reportIncomingCall is not wrapped by setTimeout, the app behaves as expected: a call is reported, even if not in foreground.

(NB: I used a regular push notification to trigger all my sample code)