Guard creation of external signaling controller with background task

Signed-off-by: Marcel Müller <marcel-mueller@gmx.de>
This commit is contained in:
Marcel Müller 2022-12-30 20:01:59 +01:00
Родитель 83d52231f6
Коммит 3b624dee0f
1 изменённых файлов: 7 добавлений и 1 удалений

Просмотреть файл

@ -458,13 +458,17 @@ NSString * const kDidReceiveCallsFromOldAccount = @"receivedCallsFromOldAccount"
- (void)setSignalingConfigurationForAccountId:(NSString *)accountId
{
NSDictionary *signalingConfiguration = [_signalingConfigutations objectForKey:accountId];
NSString *externalSignalingTicket = [signalingConfiguration objectForKey:@"ticket"];
NSString *externalSignalingServer = nil;
id server = [signalingConfiguration objectForKey:@"server"];
if ([server isKindOfClass:[NSString class]] && ![server isEqualToString:@""]) {
externalSignalingServer = server;
}
NSString *externalSignalingTicket = [signalingConfiguration objectForKey:@"ticket"];
if (externalSignalingServer && externalSignalingTicket) {
BGTaskHelper *bgTask = [BGTaskHelper startBackgroundTaskWithName:@"NCSetSignalingConfiguration" expirationHandler:nil];
dispatch_async(dispatch_get_main_queue(), ^{
NCExternalSignalingController *extSignalingController = [self->_externalSignalingControllers objectForKey:accountId];
@ -475,6 +479,8 @@ NSString * const kDidReceiveCallsFromOldAccount = @"receivedCallsFromOldAccount"
TalkAccount *account = [[NCDatabaseManager sharedInstance] talkAccountForAccountId:accountId];
extSignalingController = [[NCExternalSignalingController alloc] initWithAccount:account server:externalSignalingServer andTicket:externalSignalingTicket];
[self->_externalSignalingControllers setObject:extSignalingController forKey:accountId];
[bgTask stopBackgroundTask];
});
}
}