twilio/voice-quickstart-objc

Problem with rejecting a call in iOS12

nicolettemanas opened this issue · 11 comments

Description

There seems to be an issue when trying to reject a call from an iOS12 device. The caller is not receiving any reject voip push notification.

Steps to Reproduce

  1. Make sure Bob's device is running on iOS12 and the app is terminated
  2. Alice calls Bob
  3. Bob rejects the call (via CallKit reject button)

Expected Behavior

Calls on both devices must end

Actual Behavior

Bob's call ends, Alice's call is still ringing. No reject VOIP push notif received on Alice's end.

Reproduces How Often

100%

Versions

TwilioVoice 2.0.6 via CocoaPods

Xcode

XCode 10 beta

iOS Version

iOS12 beta 6

iOS Device

iPhone 6 Plus iOS12 beta 6
iPhone 6s iOS11

Hi @nicolettemanas

Thanks for reporting the issue.
I am also able to reproduce the problem, although first I had to use a dispatch global queue to initialize the PushKit registry so the application can report the call to CallKit when the call is received while the app was terminated.
I'll need to so some debug to see while the reject operation is not properly executed in this scenario and will let you know if we have any update.

-bobie

Hi @bchen-twilio
Are there any updates on the issue? Let me know if you need further details.

-Jean

Hi @nicolettemanas

We haven't made much progress on this issue, but from the feedback of some SDK users, they are able to greatly reduce the reproducibility by initializing the PkPushRegistry instance in a concurrent queue so that things move more smoothly in case the app has been terminated and relaunched by the incoming call notification.

Let me know.
-bobie

@nicolettemanas I apologize for the delayed response. Just wanted to point out that, we are working this issue and will soon have an update for you. Again thanks for reporting the issue.

Best,
Piyush

Hi @nicolettemanas

Sorry for my lack of updates. We've just updated the quickstart sample apps recently and added a couple fixes to address some of the background-suspended issues in iOS 12. You can refer to this pull-request and apply necessary updates to your application.

Please let us know if this helps
Thanks!
-bobie

@nicolettemanas

I am closing this issue assuming the fix we provided in the pull request has addressed the original issue you reported. Please feel free to reopen or open new issues in the future.

Thanks,
-bobie

Reopened the issue as we we were able to reproduce the problem on iOS 13 Beta5. However it was hard to reproduce the bug in our experiments.

Root Cause

When the app is background suspended, when an incoming call VoIP push notification is received, app reports the new call to CallKit and app runs in the background. CallKit UI keeps app running (non suspended) in background. Now when user rejects the Call on CallKit UI, if app goes into background suspended state before the Voice SDK reports the reject remote side, the caller does not have a way to detect that the called party has rejected the Call.

Work around

Run a background task upon reject. Here is the code snippet -

- (void)provider:(CXProvider *)provider performEndCallAction:(CXEndCallAction *)action {
    if (self.callInvite) {
        [self.callInvite reject];
        self.callInvite = nil;

        // If user rejects the call when app is backgrounded, reject may be completed before the app goes
        // into the suspended state. Giving some time to reject to complete by starting a background task.

        if ([[UIApplication sharedApplication] applicationState] == UIApplicationStateBackground) {
            NSLog(@"Rejecting call in background, starting the background task complete the reject.");

            self.backgroundRejectTask = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{
                [[UIApplication sharedApplication] endBackgroundTask: self.backgroundRejectTask];
                self.backgroundRejectTask = UIBackgroundTaskInvalid;
                NSLog(@"background task ended");
            }];
        }
    } else if (self.call) {
        [self.call disconnect];
    }
    
    self.audioDevice.enabled = YES;
    [action fulfill];
}

Solution

We recognize this issue and we plan to provide fix in our 4.x Voice SDK in upcoming releases so that developers wont have to implement the workaround in their app.

I will update this ticket when we ship the fix.

I'm getting the same issue on IOS 13.1. I'm also not getting incoming calls if the app is on background.

Hi @jpmermoz

We are actively working on the issue regarding reject and will provide a release of the Voice iOS SDK soon. Please stay tuned.

Thanks,
-bobie

Hi @bchen-twilio , thank you!

Hi @nicolettemanas, @jpmermoz

We have just released our 5.0.0 Voice iOS SDK, which include the background task fix for this problem. We have made some API updates in order for apps built for iOS 13 with Xcode 11 to comply to the new PushKit policy introduced by Apple. For more information please check out the migration guide.

Cheers,
-bobie