Improvements in notification registration flow

This commit is contained in:
Denis Morozov
2017-08-23 19:07:14 +03:00
parent 0ead3a8483
commit b0a0dba250
3 changed files with 57 additions and 5 deletions
+23 -4
View File
@@ -2562,7 +2562,8 @@ typedef void (^blockSettingsViewController_onReadyToDestroy)();
- (void)togglePushNotifications:(id)sender
{
// Check first whether the user allow notification from device settings
if ([[MXKAccountManager sharedManager] isAPNSAvailable] == NO)
UIUserNotificationType currentUserNotificationTypes = UIApplication.sharedApplication.currentUserNotificationSettings.types;
if (currentUserNotificationTypes == UIUserNotificationTypeNone)
{
[currentAlert dismissViewControllerAnimated:NO completion:nil];
@@ -2594,10 +2595,28 @@ typedef void (^blockSettingsViewController_onReadyToDestroy)();
{
[self startActivityIndicator];
MXKAccount* account = [MXKAccountManager sharedManager].activeAccounts.firstObject;
MXKAccountManager *accountManager = [MXKAccountManager sharedManager];
MXKAccount* account = accountManager.activeAccounts.firstObject;
// toggle the pushes
[account setEnablePushNotifications:!account.pushNotificationServiceIsActive];
if (accountManager.apnsDeviceToken)
{
[account setEnablePushNotifications:!account.pushNotificationServiceIsActive];
}
else
{
// Obtain device token when user has just enabled access to notifications from system settings
[[AppDelegate theDelegate] registerForRemoteNotificationsWithCompletion:^(NSError * error) {
if (error)
{
[(UISwitch *)sender setOn:NO animated:YES];
[self stopActivityIndicator];
}
else
{
[account setEnablePushNotifications:YES];
}
}];
}
}
}