mirror of
https://github.com/vector-im/element-ios.git
synced 2024-09-29 07:42:40 +00:00
Merge pull request #1475 from morozkin/callkit_notif
Add background mode handling
This commit is contained in:
commit
3bb1a72402
1 changed files with 30 additions and 0 deletions
|
@ -1910,6 +1910,36 @@ NSString *const kAppDelegateNetworkStatusDidChangeNotification = @"kAppDelegateN
|
|||
currentCallViewController.mxCall = mxCall;
|
||||
currentCallViewController.delegate = self;
|
||||
|
||||
UIApplicationState applicationState = UIApplication.sharedApplication.applicationState;
|
||||
|
||||
// App has been woken by PushKit notification in the background
|
||||
if (applicationState == UIApplicationStateBackground && mxCall.isIncoming)
|
||||
{
|
||||
// Create backgound task.
|
||||
// Without CallKit this will allow us to play vibro until the call was ended
|
||||
// With CallKit we'll inform the system when the call is ended to let the system terminate our app to save resources
|
||||
id<MXBackgroundModeHandler> handler = [MXSDKOptions sharedInstance].backgroundModeHandler;
|
||||
NSUInteger callTaskIdentifier = [handler startBackgroundTaskWithName:nil completion:^{}];
|
||||
|
||||
// Start listening for call state change notifications
|
||||
__weak NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter];
|
||||
__block id token = [[NSNotificationCenter defaultCenter] addObserverForName:kMXCallStateDidChange
|
||||
object:mxCall
|
||||
queue:nil
|
||||
usingBlock:^(NSNotification * _Nonnull note) {
|
||||
MXCall *call = (MXCall *)note.object;
|
||||
|
||||
if (call.state == MXCallStateEnded)
|
||||
{
|
||||
// Set call vc to nil to let our app handle new incoming calls even it wasn't killed by the system
|
||||
currentCallViewController = nil;
|
||||
[notificationCenter removeObserver:token];
|
||||
|
||||
[handler endBackgrounTaskWithIdentifier:callTaskIdentifier];
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
||||
if (mxCall.isIncoming && !isCallKitAvailable)
|
||||
{
|
||||
// Prompt user before presenting the call view controller
|
||||
|
|
Loading…
Reference in a new issue