Merge pull request #1519 from vector-im/callkit_remove_apns_use

Pushkit: Remove APNS use.
This commit is contained in:
giomfo 2017-09-19 17:16:20 +02:00 committed by GitHub
commit 39d13824c6
4 changed files with 33 additions and 28 deletions

View file

@ -43,7 +43,7 @@ extern NSString *const kAppDelegateNetworkStatusDidChangeNotification;
@interface AppDelegate : UIResponder <UIApplicationDelegate, MXKCallViewControllerDelegate, UISplitViewControllerDelegate, UINavigationControllerDelegate, JitsiViewControllerDelegate>
{
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;

View file

@ -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];

View file

@ -12,6 +12,8 @@
<string>im.vector.app.ios.dev</string>
<key>pusherAppIdProd</key>
<string>im.vector.app.ios.prod</string>
<key>pushKitAppIdProd</key>
<string>im.vector.app.ios.voip.prod</string>
<key>identityserverurl</key>
<string>https://vector.im</string>
<key>homeserverurl</key>
@ -28,8 +30,6 @@
<string>https://scalar-staging.riot.im/scalar-web/</string>
<key>integrationsRestUrl</key>
<string>https://scalar-staging.riot.im/scalar/api</string>
<key>apnsDeviceToken</key>
<string></string>
<key>showAllEventsInRoomHistory</key>
<false/>
<key>showRedactionsInRoomHistory</key>

View file

@ -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];
}
}];
}