Adding conditional check to restartApp

This commit is contained in:
Jonathan Carter
2015-12-25 21:36:02 -08:00
parent 526aeff6d9
commit 464dae11ee
2 changed files with 14 additions and 6 deletions

View File

@@ -203,11 +203,11 @@ static NSString *const PackageIsPendingKey = @"isPending";
NSUserDefaults *preferences = [NSUserDefaults standardUserDefaults];
NSDictionary *pendingUpdate = [preferences objectForKey:PendingUpdateKey];
// If there is a pending update, whose hash is equal to the one
// specified, and its "state" isn't loading, then we consider it "pending".
// If there is a pending update whose "state" isn't loading, then we consider it "pending".
// Additionally, if a specific hash was provided, we ensure it matches that of the pending update.
BOOL updateIsPending = pendingUpdate &&
[pendingUpdate[PendingUpdateIsLoadingKey] boolValue] == NO &&
[pendingUpdate[PendingUpdateHashKey] isEqualToString:packageHash];
(!packageHash || [pendingUpdate[PendingUpdateHashKey] isEqualToString:packageHash]);
return updateIsPending;
}
@@ -467,9 +467,13 @@ RCT_EXPORT_METHOD(notifyApplicationReady:(RCTPromiseResolveBlock)resolve
/*
* This method is the native side of the CodePush.restartApp() method.
*/
RCT_EXPORT_METHOD(restartApp)
RCT_EXPORT_METHOD(restartApp:(BOOL)onlyIfUpdateIsPending)
{
[self loadBundle];
// If this is an unconditional restart request, or there
// is current pending update, then reload the app.
if (!onlyIfUpdateIsPending || [self isPendingUpdate:nil]) {
[self loadBundle];
}
}
/*