mirror of
https://github.com/vector-im/element-ios.git
synced 2024-09-28 23:32:41 +00:00
AppDelegate: Handle updated MXBackgroundModeHandler and now use MXBackgroundTask.
This commit is contained in:
parent
ea5e5e28db
commit
83b4315d6a
1 changed files with 13 additions and 8 deletions
|
@ -759,11 +759,15 @@ NSString *const AppDelegateDidValidateEmailNotificationClientSecretKey = @"AppDe
|
|||
BOOL isVideoCall = [userActivity.activityType isEqualToString:INStartVideoCallIntentIdentifier];
|
||||
|
||||
UIApplication *application = UIApplication.sharedApplication;
|
||||
NSNumber *backgroundTaskIdentifier;
|
||||
|
||||
id<MXBackgroundModeHandler> handler = [MXSDKOptions sharedInstance].backgroundModeHandler;
|
||||
id<MXBackgroundTask> backgroundTask;
|
||||
|
||||
// Start background task since we need time for MXSession preparasion because our app can be launched in the background
|
||||
if (application.applicationState == UIApplicationStateBackground)
|
||||
backgroundTaskIdentifier = @([application beginBackgroundTaskWithExpirationHandler:^{}]);
|
||||
{
|
||||
backgroundTask = [handler startBackgroundTaskWithName:@"[AppDelegate] application:continueUserActivity:restorationHandler: Audio or video call" expirationHandler:nil];
|
||||
}
|
||||
|
||||
MXSession *session = mxSessionArray.firstObject;
|
||||
[session.callManager placeCallInRoom:roomID
|
||||
|
@ -779,15 +783,17 @@ NSString *const AppDelegateDidValidateEmailNotificationClientSecretKey = @"AppDe
|
|||
usingBlock:^(NSNotification * _Nonnull note) {
|
||||
if (call.state == MXCallStateEnded)
|
||||
{
|
||||
[application endBackgroundTask:backgroundTaskIdentifier.unsignedIntegerValue];
|
||||
[backgroundTask stop];
|
||||
[center removeObserver:token];
|
||||
}
|
||||
}];
|
||||
}
|
||||
}
|
||||
failure:^(NSError *error) {
|
||||
if (backgroundTaskIdentifier)
|
||||
[application endBackgroundTask:backgroundTaskIdentifier.unsignedIntegerValue];
|
||||
if (backgroundTask)
|
||||
{
|
||||
[backgroundTask stop];
|
||||
}
|
||||
}];
|
||||
|
||||
continueUserActivity = YES;
|
||||
|
@ -3299,7 +3305,7 @@ NSString *const AppDelegateDidValidateEmailNotificationClientSecretKey = @"AppDe
|
|||
// 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:^{}];
|
||||
id<MXBackgroundTask> callBackgroundTask = [handler startBackgroundTaskWithName:@"[AppDelegate] addMatrixCallObserver" expirationHandler:nil];
|
||||
|
||||
// Start listening for call state change notifications
|
||||
__weak NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter];
|
||||
|
@ -3314,8 +3320,7 @@ NSString *const AppDelegateDidValidateEmailNotificationClientSecretKey = @"AppDe
|
|||
// 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];
|
||||
[callBackgroundTask stop];
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue