diff --git a/Riot/Managers/PushNotification/PushNotificationService.m b/Riot/Managers/PushNotification/PushNotificationService.m index fc6eab47d..13db25148 100644 --- a/Riot/Managers/PushNotification/PushNotificationService.m +++ b/Riot/Managers/PushNotification/PushNotificationService.m @@ -266,6 +266,15 @@ Matrix session observer used to detect new opened sessions. - (void)configurePushKit { MXLogDebug(@"[PushNotificationService] configurePushKit") + NSData* token = [_pushRegistry pushTokenForType:PKPushTypeVoIP]; + if (token) { + // If the token is available, store it. This can happen if you sign out and back in. + // i.e We are registered, but we have cleared it from the the store on logout and the + // _pushRegistry lives through signin/signout as PushNotificationService is a singleton + // on app delegate. + _pushNotificationStore.pushKitToken = token; + MXLogDebug(@"[PushNotificationService] configurePushKit: Restored pushKit token") + } _pushRegistry.delegate = self; _pushRegistry.desiredPushTypes = [NSSet setWithObject:PKPushTypeVoIP]; diff --git a/RiotNSE/NotificationService.swift b/RiotNSE/NotificationService.swift index 99a9bba12..f6125baca 100644 --- a/RiotNSE/NotificationService.swift +++ b/RiotNSE/NotificationService.swift @@ -66,7 +66,7 @@ class NotificationService: UNNotificationServiceExtension { }() private var pushNotificationStore: PushNotificationStore = PushNotificationStore() private let localAuthenticationService = LocalAuthenticationService(pinCodePreferences: .shared) - + private static let backgroundServiceInitQueue = DispatchQueue(label: "io.element.NotificationService.backgroundServiceInitQueue") // MARK: - Method Overrides override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) { @@ -169,14 +169,16 @@ class NotificationService: UNNotificationServiceExtension { MXKAccountManager.shared()?.forceReloadAccounts() self.userAccount = MXKAccountManager.shared()?.activeAccounts.first if let userAccount = userAccount { - if NotificationService.backgroundSyncService?.credentials != userAccount.mxCredentials { - MXLog.debug("[NotificationService] setup: MXBackgroundSyncService init: BEFORE") - self.logMemory() - NotificationService.backgroundSyncService = MXBackgroundSyncService(withCredentials: userAccount.mxCredentials) - MXLog.debug("[NotificationService] setup: MXBackgroundSyncService init: AFTER") - self.logMemory() + Self.backgroundServiceInitQueue.sync { + if NotificationService.backgroundSyncService?.credentials != userAccount.mxCredentials { + MXLog.debug("[NotificationService] setup: MXBackgroundSyncService init: BEFORE") + self.logMemory() + NotificationService.backgroundSyncService = MXBackgroundSyncService(withCredentials: userAccount.mxCredentials) + MXLog.debug("[NotificationService] setup: MXBackgroundSyncService init: AFTER") + self.logMemory() + } + completion() } - completion() } else { MXLog.debug("[NotificationService] setup: No active accounts") fallbackToBestAttemptContent(forEventId: eventId) diff --git a/changelog.d/5199.bugfix b/changelog.d/5199.bugfix new file mode 100644 index 000000000..d363f1449 --- /dev/null +++ b/changelog.d/5199.bugfix @@ -0,0 +1 @@ +Fix bug where VoIP calls would not connect reliably after signout/signin.