mirror of
https://github.com/vector-im/element-ios.git
synced 2024-09-28 23:32:41 +00:00
Merge pull request #3558 from vector-im/element_3452_remarks
Fix Later Remarks on PushKit & CallKit
This commit is contained in:
commit
a9ed30b2cc
6 changed files with 39 additions and 41 deletions
|
@ -841,8 +841,8 @@
|
|||
EC85D754247C0F5B002C44C9 /* Constants.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC85D753247C0F5B002C44C9 /* Constants.swift */; };
|
||||
EC85D755247C0F84002C44C9 /* Constants.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC85D753247C0F5B002C44C9 /* Constants.swift */; };
|
||||
EC85D757247E700F002C44C9 /* NSEMemoryStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC85D756247E700F002C44C9 /* NSEMemoryStore.swift */; };
|
||||
EC9A3EC524E1616900A8CFAE /* PushNotificationManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC9A3EC424E1616900A8CFAE /* PushNotificationManager.swift */; };
|
||||
EC9A3EC624E1632C00A8CFAE /* PushNotificationManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC9A3EC424E1616900A8CFAE /* PushNotificationManager.swift */; };
|
||||
EC9A3EC524E1616900A8CFAE /* PushNotificationStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC9A3EC424E1616900A8CFAE /* PushNotificationStore.swift */; };
|
||||
EC9A3EC624E1632C00A8CFAE /* PushNotificationStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC9A3EC424E1616900A8CFAE /* PushNotificationStore.swift */; };
|
||||
EC9A3EC724E1634100A8CFAE /* KeyValueStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC1CA87124C823E700DE9EBF /* KeyValueStore.swift */; };
|
||||
EC9A3EC824E1634800A8CFAE /* KeychainStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC1CA87424C8259700DE9EBF /* KeychainStore.swift */; };
|
||||
ECAE7AE524EC0E01002FA813 /* TableViewSections.swift in Sources */ = {isa = PBXBuildFile; fileRef = ECAE7AE424EC0E01002FA813 /* TableViewSections.swift */; };
|
||||
|
@ -1972,7 +1972,7 @@
|
|||
EC85D750247C0E8F002C44C9 /* UNUserNotificationCenter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UNUserNotificationCenter.swift; sourceTree = "<group>"; };
|
||||
EC85D753247C0F5B002C44C9 /* Constants.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Constants.swift; sourceTree = "<group>"; };
|
||||
EC85D756247E700F002C44C9 /* NSEMemoryStore.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NSEMemoryStore.swift; sourceTree = "<group>"; };
|
||||
EC9A3EC424E1616900A8CFAE /* PushNotificationManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PushNotificationManager.swift; sourceTree = "<group>"; };
|
||||
EC9A3EC424E1616900A8CFAE /* PushNotificationStore.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PushNotificationStore.swift; sourceTree = "<group>"; };
|
||||
ECAE7AE424EC0E01002FA813 /* TableViewSections.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TableViewSections.swift; sourceTree = "<group>"; };
|
||||
ECAE7AE624EC15F7002FA813 /* Section.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Section.swift; sourceTree = "<group>"; };
|
||||
ECAE7AE824EC1888002FA813 /* Row.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Row.swift; sourceTree = "<group>"; };
|
||||
|
@ -4827,7 +4827,7 @@
|
|||
children = (
|
||||
EC85D73C2477DDD0002C44C9 /* PushNotificationService.h */,
|
||||
EC85D73D2477DDD0002C44C9 /* PushNotificationService.m */,
|
||||
EC9A3EC424E1616900A8CFAE /* PushNotificationManager.swift */,
|
||||
EC9A3EC424E1616900A8CFAE /* PushNotificationStore.swift */,
|
||||
);
|
||||
path = PushNotification;
|
||||
sourceTree = "<group>";
|
||||
|
@ -5705,7 +5705,7 @@
|
|||
EC2B4EF224A1EF34005EB739 /* DataProtectionHelper.swift in Sources */,
|
||||
EC85D7462477E5F7002C44C9 /* NotificationService.swift in Sources */,
|
||||
32FD755424D074C700BA7B37 /* CommonConfiguration.swift in Sources */,
|
||||
EC9A3EC624E1632C00A8CFAE /* PushNotificationManager.swift in Sources */,
|
||||
EC9A3EC624E1632C00A8CFAE /* PushNotificationStore.swift in Sources */,
|
||||
32FD757424D2BEF700BA7B37 /* InfoPlist.swift in Sources */,
|
||||
EC85D752247C0F52002C44C9 /* UNUserNotificationCenter.swift in Sources */,
|
||||
EC9A3EC724E1634100A8CFAE /* KeyValueStore.swift in Sources */,
|
||||
|
@ -6168,7 +6168,7 @@
|
|||
EC711BA924A63B58008F830C /* SecureBackupSetupCoordinatorBridgePresenter.swift in Sources */,
|
||||
B1B558C720EF768F00210D55 /* RoomOutgoingEncryptedTextMsgWithPaginationTitleBubbleCell.m in Sources */,
|
||||
B1B336C5242B933700F95EC4 /* KeyVerificationSelfVerifyStartViewModel.swift in Sources */,
|
||||
EC9A3EC524E1616900A8CFAE /* PushNotificationManager.swift in Sources */,
|
||||
EC9A3EC524E1616900A8CFAE /* PushNotificationStore.swift in Sources */,
|
||||
B1B558F020EF768F00210D55 /* RoomOutgoingAttachmentWithPaginationTitleBubbleCell.m in Sources */,
|
||||
926FA53F1F4C132000F826C2 /* MXSession+Riot.m in Sources */,
|
||||
EC711B8324A63B37008F830C /* SecretsSetupRecoveryPassphraseCoordinator.swift in Sources */,
|
||||
|
|
|
@ -237,6 +237,7 @@ NSString *const AppDelegateUniversalLinkDidChangeNotification = @"AppDelegateUni
|
|||
Related push notification service instance. Will be created when launch finished.
|
||||
*/
|
||||
@property (nonatomic, strong) PushNotificationService *pushNotificationService;
|
||||
@property (nonatomic, strong) PushNotificationStore *pushNotificationStore;
|
||||
@property (nonatomic, strong) LocalAuthenticationService *localAuthenticationService;
|
||||
|
||||
@property (nonatomic, strong) MajorUpdateManager *majorUpdateManager;
|
||||
|
@ -510,7 +511,8 @@ NSString *const AppDelegateUniversalLinkDidChangeNotification = @"AppDelegateUni
|
|||
|
||||
self.localAuthenticationService = [[LocalAuthenticationService alloc] initWithPinCodePreferences:[PinCodePreferences shared]];
|
||||
|
||||
self.pushNotificationService = [[PushNotificationService alloc] initWithPushNotificationManager:PushNotificationManager.shared];
|
||||
self.pushNotificationStore = [PushNotificationStore new];
|
||||
self.pushNotificationService = [[PushNotificationService alloc] initWithPushNotificationStore:self.pushNotificationStore];
|
||||
self.pushNotificationService.delegate = self;
|
||||
|
||||
// Add matrix observers, and initialize matrix sessions if the app is not launched in background.
|
||||
|
@ -2250,8 +2252,8 @@ NSString *const AppDelegateUniversalLinkDidChangeNotification = @"AppDelegateUni
|
|||
// Reset user pin code
|
||||
[PinCodePreferences.shared reset];
|
||||
|
||||
// Reset push notification manager
|
||||
[PushNotificationManager.shared reset];
|
||||
// Reset push notification store
|
||||
[self.pushNotificationStore reset];
|
||||
|
||||
#ifdef MX_CALL_STACK_ENDPOINT
|
||||
// Erase all created certificates and private keys by MXEndpointCallStack
|
||||
|
|
|
@ -34,8 +34,8 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
+ (instancetype)new NS_UNAVAILABLE;
|
||||
|
||||
/// Designated initializer
|
||||
/// @param pushNotificationManager Push Notification Manager instance
|
||||
- (instancetype)initWithPushNotificationManager:(PushNotificationManager *)pushNotificationManager;
|
||||
/// @param pushNotificationStore Push Notification Store instance
|
||||
- (instancetype)initWithPushNotificationStore:(PushNotificationStore *)pushNotificationStore;
|
||||
|
||||
/**
|
||||
Is push really registered.
|
||||
|
|
|
@ -22,16 +22,14 @@
|
|||
#import <PushKit/PushKit.h>
|
||||
|
||||
@interface PushNotificationService()<PKPushRegistryDelegate>
|
||||
{
|
||||
/**
|
||||
Matrix session observer used to detect new opened sessions.
|
||||
*/
|
||||
id matrixSessionStateObserver;
|
||||
}
|
||||
|
||||
/**
|
||||
Matrix session observer used to detect new opened sessions.
|
||||
*/
|
||||
@property (nonatomic, weak) id matrixSessionStateObserver;
|
||||
@property (nonatomic, nullable, copy) void (^registrationForRemoteNotificationsCompletion)(NSError *);
|
||||
@property (nonatomic, strong) PKPushRegistry *pushRegistry;
|
||||
@property (nonatomic, strong) PushNotificationManager *pushNotificationManager;
|
||||
@property (nonatomic, strong) PushNotificationStore *pushNotificationStore;
|
||||
|
||||
/// Should PushNotificationService receive VoIP pushes
|
||||
@property (nonatomic, assign) BOOL shouldReceiveVoIPPushes;
|
||||
|
@ -40,11 +38,11 @@
|
|||
|
||||
@implementation PushNotificationService
|
||||
|
||||
- (instancetype)initWithPushNotificationManager:(PushNotificationManager *)pushNotificationManager
|
||||
- (instancetype)initWithPushNotificationStore:(PushNotificationStore *)pushNotificationStore
|
||||
{
|
||||
if (self = [super init])
|
||||
{
|
||||
self.pushNotificationManager = pushNotificationManager;
|
||||
self.pushNotificationStore = pushNotificationStore;
|
||||
_pushRegistry = [[PKPushRegistry alloc] initWithQueue:dispatch_get_main_queue()];
|
||||
self.shouldReceiveVoIPPushes = YES;
|
||||
}
|
||||
|
@ -117,7 +115,7 @@
|
|||
|
||||
_isPushRegistered = YES;
|
||||
|
||||
if (!_pushNotificationManager.pushKitToken)
|
||||
if (!_pushNotificationStore.pushKitToken)
|
||||
{
|
||||
[self configurePushKit];
|
||||
}
|
||||
|
@ -162,7 +160,7 @@
|
|||
|
||||
- (void)applicationDidEnterBackground
|
||||
{
|
||||
if (_pushNotificationManager.pushKitToken)
|
||||
if (_pushNotificationStore.pushKitToken)
|
||||
{
|
||||
self.shouldReceiveVoIPPushes = YES;
|
||||
}
|
||||
|
@ -172,7 +170,7 @@
|
|||
{
|
||||
[[UNUserNotificationCenter currentNotificationCenter] removeUnwantedNotifications];
|
||||
[[UNUserNotificationCenter currentNotificationCenter] removeCallNotificationsFor:nil];
|
||||
if (_pushNotificationManager.pushKitToken)
|
||||
if (_pushNotificationStore.pushKitToken)
|
||||
{
|
||||
self.shouldReceiveVoIPPushes = NO;
|
||||
}
|
||||
|
@ -184,7 +182,7 @@
|
|||
{
|
||||
_shouldReceiveVoIPPushes = shouldReceiveVoIPPushes;
|
||||
|
||||
if (_shouldReceiveVoIPPushes && _pushNotificationManager.pushKitToken)
|
||||
if (_shouldReceiveVoIPPushes && _pushNotificationStore.pushKitToken)
|
||||
{
|
||||
MXSession *session = [AppDelegate theDelegate].mxSessions.firstObject;
|
||||
if (session.state >= MXSessionStateStoreDataReady)
|
||||
|
@ -194,7 +192,11 @@
|
|||
else
|
||||
{
|
||||
// add an observer for session state
|
||||
matrixSessionStateObserver = [[NSNotificationCenter defaultCenter] addObserverForName:kMXSessionStateDidChangeNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *notif) {
|
||||
MXWeakify(self);
|
||||
|
||||
NSNotificationCenter * __weak notificationCenter = [NSNotificationCenter defaultCenter];
|
||||
self.matrixSessionStateObserver = [[NSNotificationCenter defaultCenter] addObserverForName:kMXSessionStateDidChangeNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *notif) {
|
||||
MXStrongifyAndReturnIfNil(self);
|
||||
MXSession *mxSession = (MXSession*)notif.object;
|
||||
|
||||
if ([[AppDelegate theDelegate].mxSessions containsObject:mxSession]
|
||||
|
@ -202,8 +204,7 @@
|
|||
&& self->_shouldReceiveVoIPPushes)
|
||||
{
|
||||
[self configurePushKit];
|
||||
[[NSNotificationCenter defaultCenter] removeObserver:self->matrixSessionStateObserver];
|
||||
self->matrixSessionStateObserver = nil;
|
||||
[notificationCenter removeObserver:self.matrixSessionStateObserver];
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
@ -230,15 +231,12 @@
|
|||
if (account.mxSession.state == MXSessionStatePaused)
|
||||
{
|
||||
NSLog(@"[PushNotificationService] launchBackgroundSync");
|
||||
__weak typeof(self) weakSelf = self;
|
||||
MXWeakify(self);
|
||||
|
||||
[account backgroundSync:20000 success:^{
|
||||
|
||||
// Sanity check
|
||||
if (!weakSelf)
|
||||
{
|
||||
return;
|
||||
}
|
||||
MXStrongifyAndReturnIfNil(self);
|
||||
|
||||
[[UNUserNotificationCenter currentNotificationCenter] removeUnwantedNotifications];
|
||||
[[UNUserNotificationCenter currentNotificationCenter] removeCallNotificationsFor:nil];
|
||||
|
@ -450,7 +448,7 @@
|
|||
- (void)pushRegistry:(PKPushRegistry *)registry didUpdatePushCredentials:(PKPushCredentials *)pushCredentials forType:(PKPushType)type
|
||||
{
|
||||
NSLog(@"[PushNotificationService] did update PushKit credentials");
|
||||
_pushNotificationManager.pushKitToken = pushCredentials.token;
|
||||
_pushNotificationStore.pushKitToken = pushCredentials.token;
|
||||
if ([UIApplication sharedApplication].applicationState == UIApplicationStateActive)
|
||||
{
|
||||
self.shouldReceiveVoIPPushes = NO;
|
||||
|
@ -474,9 +472,9 @@
|
|||
if (@available(iOS 13.0, *))
|
||||
{
|
||||
// for iOS 13, we'll just report the incoming call in the same runloop. It means we cannot call an async API here.
|
||||
MXEvent *lastCallInvite = _pushNotificationManager.lastCallInvite;
|
||||
MXEvent *lastCallInvite = _pushNotificationStore.lastCallInvite;
|
||||
// remove event
|
||||
_pushNotificationManager.lastCallInvite = nil;
|
||||
_pushNotificationStore.lastCallInvite = nil;
|
||||
MXSession *session = [AppDelegate theDelegate].mxSessions.firstObject;
|
||||
// when we have a VoIP push while the application is killed, session.callManager will not be ready yet. Configure it.
|
||||
[[AppDelegate theDelegate] configureCallManagerIfRequiredForSession:session];
|
||||
|
|
|
@ -19,7 +19,7 @@ import KeychainAccess
|
|||
import MatrixSDK
|
||||
|
||||
@objcMembers
|
||||
final class PushNotificationManager: NSObject {
|
||||
final class PushNotificationStore: NSObject {
|
||||
|
||||
// MARK: - Constants
|
||||
|
||||
|
@ -32,8 +32,6 @@ final class PushNotificationManager: NSObject {
|
|||
static let lastCallInvite: String = "lastCallInvite"
|
||||
}
|
||||
|
||||
static let shared = PushNotificationManager()
|
||||
|
||||
/// Store. Defaults to `KeychainStore`
|
||||
private let store: KeyValueStore
|
||||
|
|
@ -40,7 +40,7 @@ class NotificationService: UNNotificationServiceExtension {
|
|||
let url = URL(string: BuildSettings.serverConfigSygnalAPIUrlString)!
|
||||
return MXPushGatewayRestClient(pushGateway: url.scheme! + "://" + url.host!, andOnUnrecognizedCertificateBlock: nil)
|
||||
}()
|
||||
private var pushNotificationManager: PushNotificationManager = .shared
|
||||
private var pushNotificationStore: PushNotificationStore = PushNotificationStore()
|
||||
|
||||
override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) {
|
||||
// Set static application settings
|
||||
|
@ -549,11 +549,11 @@ class NotificationService: UNNotificationServiceExtension {
|
|||
/// Attempts to send trigger a VoIP push for the given event
|
||||
/// - Parameter event: The call invite event.
|
||||
private func sendVoipPush(forEvent event: MXEvent) {
|
||||
guard let token = pushNotificationManager.pushKitToken else {
|
||||
guard let token = pushNotificationStore.pushKitToken else {
|
||||
return
|
||||
}
|
||||
|
||||
pushNotificationManager.lastCallInvite = event
|
||||
pushNotificationStore.lastCallInvite = event
|
||||
|
||||
let appId = BuildSettings.pushKitAppId
|
||||
|
||||
|
|
Loading…
Reference in a new issue