Sync push tokens on background launch as well

// FREEBIE
This commit is contained in:
Michael Kirk 2017-10-06 12:00:29 -04:00
parent abcf421eff
commit c7cfe188ee
1 changed files with 13 additions and 10 deletions

View File

@ -271,23 +271,26 @@ static NSString *const kURLHostVerifyPrefix = @"verify";
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
DDLogDebug(@"%@ Successfully registered for remote notifications with token: %@", self.tag, deviceToken);
DDLogDebug(@"%@ registered vanilla push token: %@", self.tag, deviceToken);
[PushManager.sharedManager.pushNotificationFutureSource trySetResult:deviceToken];
}
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
{
OWSProdError([OWSAnalyticsEvents appDelegateErrorFailedToRegisterForRemoteNotifications]);
DDLogDebug(@"%@ failed to register vanilla push token with error: %@", self.tag, error);
#ifdef DEBUG
DDLogWarn(@"%@ We're in debug mode. Faking success for remote registration with a fake push identifier", self.tag);
[PushManager.sharedManager.pushNotificationFutureSource trySetResult:[[NSMutableData dataWithLength:32] copy]];
#else
OWSProdError([OWSAnalyticsEvents appDelegateErrorFailedToRegisterForRemoteNotifications]);
[PushManager.sharedManager.pushNotificationFutureSource trySetFailure:error];
#endif
}
- (void)application:(UIApplication *)application
didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings {
didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings
{
DDLogDebug(@"%@ registered user notification settings", self.tag);
[PushManager.sharedManager.userNotificationFutureSource trySetResult:notificationSettings];
}
@ -480,13 +483,8 @@ static NSString *const kURLHostVerifyPrefix = @"verify";
// At this point, potentially lengthy DB locking migrations could be running.
// Avoid blocking app launch by putting all further possible DB access in async block
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
DDLogInfo(
@"%@ running post launch block for registered user: %@", self.tag, [TSAccountManager localNumber]);
__unused AnyPromise *promise =
[OWSSyncPushTokensJob runWithPushManager:[PushManager sharedManager]
accountManager:[Environment getCurrent].accountManager
preferences:[Environment preferences]];
DDLogInfo(@"%@ running post launch block for registered user: %@", self.tag, [TSAccountManager localNumber]);
// Clean up any messages that expired since last launch immediately
// and continue cleaning in the background.
[[OWSDisappearingMessagesJob sharedJob] startIfNecessary];
@ -819,6 +817,11 @@ static NSString *const kURLHostVerifyPrefix = @"verify";
if ([TSAccountManager isRegistered]) {
DDLogInfo(@"localNumber: %@", [TSAccountManager localNumber]);
// This should happen at any launch, background or foreground.
__unused AnyPromise *promise = [OWSSyncPushTokensJob runWithPushManager:[PushManager sharedManager]
accountManager:[Environment getCurrent].accountManager
preferences:[Environment preferences]];
}
[DeviceSleepManager.sharedInstance removeBlockWithBlockObject:self];