diff --git a/Riot/AppDelegate.h b/Riot/AppDelegate.h index dd33b3579..55b3cd54e 100644 --- a/Riot/AppDelegate.h +++ b/Riot/AppDelegate.h @@ -43,7 +43,7 @@ extern NSString *const kAppDelegateNetworkStatusDidChangeNotification; @interface AppDelegate : UIResponder { - BOOL isAPNSRegistered; + BOOL isPushRegistered; // background sync management void (^_completionHandler)(UIBackgroundFetchResult); @@ -112,7 +112,7 @@ extern NSString *const kAppDelegateNetworkStatusDidChangeNotification; - (void)startGoogleAnalytics; - (void)stopGoogleAnalytics; -#pragma mark - APNS methods +#pragma mark - Push notifications - (void)registerUserNotificationSettings; diff --git a/Riot/AppDelegate.m b/Riot/AppDelegate.m index cb193e5bd..13509940a 100644 --- a/Riot/AppDelegate.m +++ b/Riot/AppDelegate.m @@ -357,9 +357,6 @@ NSString *const kAppDelegateNetworkStatusDidChangeNotification = @"kAppDelegateN _isAppForeground = NO; - // We use now Pushkit, unregister for all remote notifications received via Apple Push Notification service. - [[UIApplication sharedApplication] unregisterForRemoteNotifications]; - // Retrieve custom configuration NSString* userDefaults = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"UserDefaults"]; NSString *defaultsPathFromApp = [[NSBundle mainBundle] pathForResource:userDefaults ofType:@"plist"]; @@ -959,11 +956,11 @@ NSString *const kAppDelegateNetworkStatusDidChangeNotification = @"kAppDelegateN } } -#pragma mark - APNS methods +#pragma mark - Push notifications - (void)registerUserNotificationSettings { - if (!isAPNSRegistered) + if (!isPushRegistered) { // Registration on iOS 8 and later UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeBadge | UIUserNotificationTypeSound |UIUserNotificationTypeAlert) categories:nil]; @@ -991,7 +988,7 @@ NSString *const kAppDelegateNetworkStatusDidChangeNotification = @"kAppDelegateN { // Clear existing token MXKAccountManager* accountManager = [MXKAccountManager sharedManager]; - [accountManager setApnsDeviceToken:nil]; + [accountManager setPushDeviceToken:nil withPushOptions:nil]; } } @@ -1043,12 +1040,12 @@ NSString *const kAppDelegateNetworkStatusDidChangeNotification = @"kAppDelegateN NSData *token = credentials.token; NSUInteger len = ((token.length > 8) ? 8 : token.length / 2); - NSLog(@"[AppDelegate] Got APNS token! (%@ ...)", [token subdataWithRange:NSMakeRange(0, len)]); + NSLog(@"[AppDelegate] Got Push token! (%@ ...)", [token subdataWithRange:NSMakeRange(0, len)]); MXKAccountManager* accountManager = [MXKAccountManager sharedManager]; - [accountManager setApnsDeviceToken:token]; + [accountManager setPushDeviceToken:token withPushOptions:@{@"format": @"event_id_only"}]; - isAPNSRegistered = YES; + isPushRegistered = YES; if (self.registrationForRemoteNotificationsCompletion) { @@ -1060,7 +1057,7 @@ NSString *const kAppDelegateNetworkStatusDidChangeNotification = @"kAppDelegateN - (void)pushRegistry:(PKPushRegistry *)registry didInvalidatePushTokenForType:(PKPushType)type { MXKAccountManager* accountManager = [MXKAccountManager sharedManager]; - [accountManager setApnsDeviceToken:nil]; + [accountManager setPushDeviceToken:nil withPushOptions:nil]; } - (void)pushRegistry:(PKPushRegistry *)registry didReceiveIncomingPushWithPayload:(PKPushPayload *)payload forType:(PKPushType)type @@ -1737,10 +1734,10 @@ NSString *const kAppDelegateNetworkStatusDidChangeNotification = @"kAppDelegateN // Set the push gateway URL. account.pushGatewayURL = [[NSUserDefaults standardUserDefaults] objectForKey:@"pushGatewayURL"]; - if (isAPNSRegistered) + if (isPushRegistered) { // Enable push notifications by default on new added account - account.enablePushNotifications = YES; + account.enablePushKitNotifications = YES; } else { @@ -1807,6 +1804,14 @@ NSString *const kAppDelegateNetworkStatusDidChangeNotification = @"kAppDelegateN // Use MXFileStore as MXStore to permanently store events. accountManager.storeClass = [MXFileStore class]; + // Disable APNS use. + if (accountManager.apnsDeviceToken) + { + // We use now Pushkit, unregister for all remote notifications received via Apple Push Notification service. + [[UIApplication sharedApplication] unregisterForRemoteNotifications]; + [accountManager setApnsDeviceToken:nil]; + } + // Observers have been defined, we can start a matrix session for each enabled accounts. NSLog(@"[AppDelegate] initMatrixSessions: prepareSessionForActiveAccounts (app state: %tu)", [[UIApplication sharedApplication] applicationState]); [accountManager prepareSessionForActiveAccounts]; @@ -1926,7 +1931,7 @@ NSString *const kAppDelegateNetworkStatusDidChangeNotification = @"kAppDelegateN - (void)logout { self.pushRegistry = nil; - isAPNSRegistered = NO; + isPushRegistered = NO; // Clear cache [MXMediaManager clearCache]; diff --git a/Riot/Riot-Defaults.plist b/Riot/Riot-Defaults.plist index da87bc19d..a8f218ea1 100644 --- a/Riot/Riot-Defaults.plist +++ b/Riot/Riot-Defaults.plist @@ -12,6 +12,8 @@ im.vector.app.ios.dev pusherAppIdProd im.vector.app.ios.prod + pushKitAppIdProd + im.vector.app.ios.voip.prod identityserverurl https://vector.im homeserverurl @@ -28,8 +30,6 @@ https://scalar-staging.riot.im/scalar-web/ integrationsRestUrl https://scalar-staging.riot.im/scalar/api - apnsDeviceToken - showAllEventsInRoomHistory showRedactionsInRoomHistory diff --git a/Riot/ViewController/SettingsViewController.m b/Riot/ViewController/SettingsViewController.m index 8c5166cd6..d9344fb67 100644 --- a/Riot/ViewController/SettingsViewController.m +++ b/Riot/ViewController/SettingsViewController.m @@ -133,7 +133,7 @@ typedef void (^blockSettingsViewController_onReadyToDestroy)(); // listener id removedAccountObserver; id accountUserInfoObserver; - id apnsInfoUpdateObserver; + id pushInfoUpdateObserver; id notificationCenterWillUpdateObserver; id notificationCenterDidUpdateObserver; @@ -283,8 +283,8 @@ typedef void (^blockSettingsViewController_onReadyToDestroy)(); }]; - // Add observer to apns - apnsInfoUpdateObserver = [[NSNotificationCenter defaultCenter] addObserverForName:kMXKAccountAPNSActivityDidChangeNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *notif) { + // Add observer to push settings + pushInfoUpdateObserver = [[NSNotificationCenter defaultCenter] addObserverForName:kMXKAccountPushKitActivityDidChangeNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *notif) { [self stopActivityIndicator]; @@ -533,10 +533,10 @@ typedef void (^blockSettingsViewController_onReadyToDestroy)(); accountUserInfoObserver = nil; } - if (apnsInfoUpdateObserver) + if (pushInfoUpdateObserver) { - [[NSNotificationCenter defaultCenter] removeObserver:apnsInfoUpdateObserver]; - apnsInfoUpdateObserver = nil; + [[NSNotificationCenter defaultCenter] removeObserver:pushInfoUpdateObserver]; + pushInfoUpdateObserver = nil; } [[NSNotificationCenter defaultCenter] removeObserver:self]; @@ -1633,7 +1633,7 @@ typedef void (^blockSettingsViewController_onReadyToDestroy)(); MXKTableViewCellWithLabelAndSwitch* labelAndSwitchCell = [self getLabelAndSwitchCell:tableView forIndexPath:indexPath]; labelAndSwitchCell.mxkLabel.text = NSLocalizedStringFromTable(@"settings_enable_push_notif", @"Vector", nil); - labelAndSwitchCell.mxkSwitch.on = account.pushNotificationServiceIsActive; + labelAndSwitchCell.mxkSwitch.on = account.isPushKitNotificationActive; labelAndSwitchCell.mxkSwitch.enabled = YES; [labelAndSwitchCell.mxkSwitch removeTarget:self action:nil forControlEvents:UIControlEventTouchUpInside]; [labelAndSwitchCell.mxkSwitch addTarget:self action:@selector(togglePushNotifications:) forControlEvents:UIControlEventTouchUpInside]; @@ -1646,7 +1646,7 @@ typedef void (^blockSettingsViewController_onReadyToDestroy)(); labelAndSwitchCell.mxkLabel.text = NSLocalizedStringFromTable(@"settings_show_decrypted_content", @"Vector", nil); labelAndSwitchCell.mxkSwitch.on = account.showDecryptedContentInNotifications; - labelAndSwitchCell.mxkSwitch.enabled = account.pushNotificationServiceIsActive; + labelAndSwitchCell.mxkSwitch.enabled = account.isPushKitNotificationActive; [labelAndSwitchCell.mxkSwitch removeTarget:self action:nil forControlEvents:UIControlEventTouchUpInside]; [labelAndSwitchCell.mxkSwitch addTarget:self action:@selector(toggleShowDecodedContent:) forControlEvents:UIControlEventTouchUpInside]; @@ -2713,9 +2713,9 @@ typedef void (^blockSettingsViewController_onReadyToDestroy)(); MXKAccountManager *accountManager = [MXKAccountManager sharedManager]; MXKAccount* account = accountManager.activeAccounts.firstObject; - if (accountManager.apnsDeviceToken) + if (accountManager.pushDeviceToken) { - [account setEnablePushNotifications:!account.pushNotificationServiceIsActive]; + [account setEnablePushKitNotifications:!account.isPushKitNotificationActive]; } else { @@ -2728,7 +2728,7 @@ typedef void (^blockSettingsViewController_onReadyToDestroy)(); } else { - [account setEnablePushNotifications:YES]; + [account setEnablePushKitNotifications:YES]; } }]; }