Skip to content
This repository was archived by the owner on May 20, 2025. It is now read-only.

Commit 18469b5

Browse files
committed
Scheduling pending update check sync
1 parent 1a7fbf6 commit 18469b5

File tree

1 file changed

+29
-27
lines changed

1 file changed

+29
-27
lines changed

CodePush.m

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -58,36 +58,38 @@ - (void)cancelRollbackTimer
5858
}
5959

6060
- (void)checkForPendingUpdate:(BOOL)isAppStart {
61-
NSUserDefaults *preferences = [NSUserDefaults standardUserDefaults];
62-
NSDictionary *pendingUpdate = [preferences objectForKey:PendingUpdateKey];
63-
64-
if (pendingUpdate)
65-
{
66-
NSError *error;
67-
NSString *pendingHash = pendingUpdate[@"hash"];
68-
NSString *currentHash = [CodePushPackage getCurrentPackageHash:&error];
61+
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
62+
NSUserDefaults *preferences = [NSUserDefaults standardUserDefaults];
63+
NSDictionary *pendingUpdate = [preferences objectForKey:PendingUpdateKey];
6964

70-
// If the current hash is equivalent to the pending hash, then the app
71-
// restart "picked up" the new update, but we need to kick off the
72-
// rollback timer and ensure that the necessary state is setup.
73-
if ([pendingHash isEqualToString:currentHash]) {
74-
// We only want to initialize the rollback timer in two scenarios:
75-
// 1) The app has been restarted, and therefore, the pending update is already applied
76-
// 2) The app has been resumed, and the pending update indicates it supports being restarted on resume
77-
if (isAppStart || (!isAppStart && [pendingUpdate[@"allowRestartOnResume"] boolValue]))
78-
{
79-
int rollbackTimeout = [pendingUpdate[@"rollbackTimeout"] intValue];
80-
81-
// If the app wasn't restarted "naturally", then we need to restart it manually
82-
BOOL needsRestart = !isAppStart;
83-
[self initializeUpdateWithRollbackTimeout:rollbackTimeout needsRestart:needsRestart];
84-
85-
// Clear the pending update and sync
86-
[preferences removeObjectForKey:PendingUpdateKey];
87-
[preferences synchronize];
65+
if (pendingUpdate)
66+
{
67+
NSError *error;
68+
NSString *pendingHash = pendingUpdate[@"hash"];
69+
NSString *currentHash = [CodePushPackage getCurrentPackageHash:&error];
70+
71+
// If the current hash is equivalent to the pending hash, then the app
72+
// restart "picked up" the new update, but we need to kick off the
73+
// rollback timer and ensure that the necessary state is setup.
74+
if ([pendingHash isEqualToString:currentHash]) {
75+
// We only want to initialize the rollback timer in two scenarios:
76+
// 1) The app has been restarted, and therefore, the pending update is already applied
77+
// 2) The app has been resumed, and the pending update indicates it supports being restarted on resume
78+
if (isAppStart || (!isAppStart && [pendingUpdate[@"allowRestartOnResume"] boolValue]))
79+
{
80+
int rollbackTimeout = [pendingUpdate[@"rollbackTimeout"] intValue];
81+
82+
// If the app wasn't restarted "naturally", then we need to restart it manually
83+
BOOL needsRestart = !isAppStart;
84+
[self initializeUpdateWithRollbackTimeout:rollbackTimeout needsRestart:needsRestart];
85+
86+
// Clear the pending update and sync
87+
[preferences removeObjectForKey:PendingUpdateKey];
88+
[preferences synchronize];
89+
}
8890
}
8991
}
90-
}
92+
});
9193
}
9294

9395
- (void)checkForPendingUpdateDuringResume {

0 commit comments

Comments
 (0)