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
This commit is contained in:
Michael Kirk 2016-10-13 14:18:59 -04:00
parent bae050480a
commit f98e57e164
1 changed files with 2 additions and 3 deletions

View File

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