From f98e57e164e6470662e8b299afe785c1609a3107 Mon Sep 17 00:00:00 2001 From: Michael Kirk Date: Thu, 13 Oct 2016 14:18:59 -0400 Subject: [PATCH] WIP: Fix hanging registration when background modes disabled fixes #1329 We must register notification settings earlier to be sure we'll be able to get the users push tokens. We were previously relying on a quirk of background fetch, a feature which we don't *actually* use, wherein it's possible to get push tokens for a user without first prompting them for their notification settings. More on this from UIApplication.h: // Calling this will result in either application:didRegisterForRemoteNotificationsWithDeviceToken: or application:didFailToRegisterForRemoteNotificationsWithError: to be called on the application delegate. // ---> Note: these callbacks will be made only if the application has successfully registered for user notifications with registerUserNotificationSettings:, or if it is enabled for Background App Refresh. - (void)registerForRemoteNotifications NS_AVAILABLE_IOS(8_0); In the previous implementation, if a user had disabled background notifications (e.g. in order to save battery), we were waiting for push tokens that would never come. However, this simple "fix" introduces a UX problem - now we prompt for an alert in the middle of our registration flow. // FREEBIE --- Signal/src/view controllers/CodeVerificationViewController.m | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Signal/src/view controllers/CodeVerificationViewController.m b/Signal/src/view controllers/CodeVerificationViewController.m index 5d40bcbbf..4c63c1b63 100644 --- a/Signal/src/view controllers/CodeVerificationViewController.m +++ b/Signal/src/view controllers/CodeVerificationViewController.m @@ -100,8 +100,6 @@ - (void)setupContacts { [[Environment getCurrent].contactsManager doAfterEnvironmentInitSetup]; - - [[PushManager sharedManager] validateUserNotificationSettings]; } - (NSString *)validationCodeFromTextField { @@ -110,7 +108,8 @@ - (TOCFuture *)pushRegistration { TOCFutureSource *pushAndRegisterFuture = [[TOCFutureSource alloc] init]; - ; + + [[PushManager sharedManager] validateUserNotificationSettings]; [[PushManager sharedManager] requestPushTokenWithSuccess:^(NSString *pushToken, NSString *voipToken) { NSMutableArray *pushTokens = [NSMutableArray arrayWithObject:pushToken];