diff --git a/CodePush.h b/CodePush.h index ee2e0fc..428c81b 100644 --- a/CodePush.h +++ b/CodePush.h @@ -25,7 +25,7 @@ // The below methods are only used during tests. + (BOOL)isUsingTestConfiguration; + (void)setUsingTestConfiguration:(BOOL)shouldUseTestConfiguration; -+ (void)clearTestUpdates; ++ (void)clearUpdates; @end @@ -84,7 +84,7 @@ failCallback:(void (^)(NSError *err))failCallback; // The below methods are only used during tests. + (void)downloadAndReplaceCurrentBundle:(NSString *)remoteBundleUrl; -+ (void)clearTestUpdates; ++ (void)clearUpdates; @end diff --git a/CodePush.m b/CodePush.m index 6820f26..d08d560 100644 --- a/CodePush.m +++ b/CodePush.m @@ -61,13 +61,16 @@ static NSString *const PackageIsPendingKey = @"isPending"; NSDictionary *appFileAttribs = [[NSFileManager defaultManager] attributesOfItemAtPath:packageFile error:nil]; NSDate *binaryDate = [binaryFileAttributes objectForKey:NSFileModificationDate]; NSDate *packageDate = [appFileAttribs objectForKey:NSFileModificationDate]; + NSString *binaryAppVersion = [[CodePushConfig current] appVersion]; + NSString *packageAppVersion = [appFileAttribs objectForKey:@"appVersion"]; - if ([binaryDate compare:packageDate] == NSOrderedAscending) { + if ([binaryDate compare:packageDate] == NSOrderedAscending && [binaryAppVersion isEqualToString:packageAppVersion]) { // Return package file because it is newer than the app store binary's JS bundle NSURL *packageUrl = [[NSURL alloc] initFileURLWithPath:packageFile]; NSLog(logMessageFormat, packageUrl); return packageUrl; } else { + [CodePush clearUpdates]; NSLog(logMessageFormat, binaryJsBundleUrl); return binaryJsBundleUrl; } @@ -100,16 +103,12 @@ static NSString *const PackageIsPendingKey = @"isPending"; } /* - * This is used to clean up all test updates. It can only be used - * when the testConfigurationFlag is set to YES, otherwise it will - * simply no-op. + * WARNING: This cleans up all downloaded and pending updates. */ -+ (void)clearTestUpdates ++ (void)clearUpdates { - if ([CodePush isUsingTestConfiguration]) { - [CodePushPackage clearTestUpdates]; - [self removePendingUpdate]; - } + [CodePushPackage clearUpdates]; + [self removePendingUpdate]; } diff --git a/CodePushPackage.m b/CodePushPackage.m index aaa2b28..b73ee41 100644 --- a/CodePushPackage.m +++ b/CodePushPackage.m @@ -505,12 +505,10 @@ NSString * const UnzippedFolderName = @"unzipped"; } } -+ (void)clearTestUpdates ++ (void)clearUpdates { - if ([CodePush isUsingTestConfiguration]) { - [[NSFileManager defaultManager] removeItemAtPath:[self getCodePushPath] error:nil]; - [[NSFileManager defaultManager] removeItemAtPath:[self getStatusFilePath] error:nil]; - } + [[NSFileManager defaultManager] removeItemAtPath:[self getCodePushPath] error:nil]; + [[NSFileManager defaultManager] removeItemAtPath:[self getStatusFilePath] error:nil]; } @end diff --git a/Examples/CodePushDemoApp/CodePushDemoAppTests/CheckForUpdateTests.m b/Examples/CodePushDemoApp/CodePushDemoAppTests/CheckForUpdateTests.m index 6b74f3a..4fe4828 100644 --- a/Examples/CodePushDemoApp/CodePushDemoAppTests/CheckForUpdateTests.m +++ b/Examples/CodePushDemoApp/CodePushDemoAppTests/CheckForUpdateTests.m @@ -25,7 +25,7 @@ NSOperatingSystemVersion version = [[NSProcessInfo processInfo] operatingSystemVersion]; RCTAssert(version.majorVersion == 8 || version.minorVersion == 3, @"Tests should be run on iOS 8.3, found %zd.%zd.%zd", version.majorVersion, version.minorVersion, version.patchVersion); [CodePush setUsingTestConfiguration:YES]; - [CodePush clearTestUpdates]; + [CodePush clearUpdates]; _runner = RCTInitRunnerForApp(@"CodePushDemoAppTests/CheckForUpdateTests/CheckForUpdateTestApp", nil); } diff --git a/Examples/CodePushDemoApp/CodePushDemoAppTests/DownloadProgressTests.m b/Examples/CodePushDemoApp/CodePushDemoAppTests/DownloadProgressTests.m index 9ed83b0..03c4c6c 100644 --- a/Examples/CodePushDemoApp/CodePushDemoAppTests/DownloadProgressTests.m +++ b/Examples/CodePushDemoApp/CodePushDemoAppTests/DownloadProgressTests.m @@ -25,7 +25,7 @@ NSOperatingSystemVersion version = [[NSProcessInfo processInfo] operatingSystemVersion]; RCTAssert(version.majorVersion == 8 || version.minorVersion == 3, @"Tests should be run on iOS 8.3, found %zd.%zd.%zd", version.majorVersion, version.minorVersion, version.patchVersion); [CodePush setUsingTestConfiguration:YES]; - [CodePush clearTestUpdates]; + [CodePush clearUpdates]; _runner = RCTInitRunnerForApp(@"CodePushDemoAppTests/DownloadProgressTests/DownloadProgressTestApp", nil); } diff --git a/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests.m b/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests.m index db365a8..3898842 100644 --- a/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests.m +++ b/Examples/CodePushDemoApp/CodePushDemoAppTests/InstallUpdateTests.m @@ -72,7 +72,7 @@ - (void)runTest:(NSString *)testName { - [CodePush clearTestUpdates]; + [CodePush clearUpdates]; RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://localhost:8081/CodePushDemoAppTests/InstallUpdateTests/testcases/%@.bundle?platform=ios&dev=true", testName]] moduleName:testName initialProperties:nil diff --git a/android/app/src/main/java/com/microsoft/codepush/react/CodePush.java b/android/app/src/main/java/com/microsoft/codepush/react/CodePush.java index 4ccb030..c3ac443 100644 --- a/android/app/src/main/java/com/microsoft/codepush/react/CodePush.java +++ b/android/app/src/main/java/com/microsoft/codepush/react/CodePush.java @@ -130,13 +130,21 @@ public class CodePush { } ReadableMap packageMetadata = codePushPackage.getCurrentPackage(); - // May throw NumberFormatException. - Long binaryModifiedDateDuringPackageInstall = Long.parseLong(CodePushUtils.tryGetString(packageMetadata, BINARY_MODIFIED_TIME_KEY)); - if (binaryModifiedDateDuringPackageInstall == binaryResourcesModifiedTime) { + Long binaryModifiedDateDuringPackageInstall = null; + String binaryModifiedDateDuringPackageInstallString = CodePushUtils.tryGetString(packageMetadata, BINARY_MODIFIED_TIME_KEY); + if (binaryModifiedDateDuringPackageInstallString != null) { + binaryModifiedDateDuringPackageInstall = Long.parseLong(binaryModifiedDateDuringPackageInstallString); + } + + String pacakgeAppVersion = CodePushUtils.tryGetString(packageMetadata, "appVersion"); + if (binaryModifiedDateDuringPackageInstall != null && + binaryModifiedDateDuringPackageInstall == binaryResourcesModifiedTime && + this.appVersion.equals(pacakgeAppVersion)) { CodePushUtils.logBundleUrl(packageFilePath); return packageFilePath; } else { // The binary version is newer. + CodePushUtils.logBundleUrl(binaryJsBundleUrl); return binaryJsBundleUrl; } @@ -299,11 +307,9 @@ public class CodePush { testConfigurationFlag = shouldUseTestConfiguration; } - public void clearTestUpdates() { - if (isUsingTestConfiguration()) { - codePushPackage.clearTestUpdates(); - removePendingUpdate(); - } + public void clearUpdates() { + codePushPackage.clearUpdates(); + removePendingUpdate(); } private class CodePushNativeModule extends ReactContextBaseJavaModule { diff --git a/android/app/src/main/java/com/microsoft/codepush/react/CodePushPackage.java b/android/app/src/main/java/com/microsoft/codepush/react/CodePushPackage.java index bb828b5..a130b42 100644 --- a/android/app/src/main/java/com/microsoft/codepush/react/CodePushPackage.java +++ b/android/app/src/main/java/com/microsoft/codepush/react/CodePushPackage.java @@ -225,11 +225,9 @@ public class CodePushPackage { } } - public void clearTestUpdates() { - if (CodePush.isUsingTestConfiguration()) { - File statusFile = new File(getStatusFilePath()); - statusFile.delete(); - CodePushUtils.deleteDirectoryAtPath(getCodePushPath()); - } + public void clearUpdates() { + File statusFile = new File(getStatusFilePath()); + statusFile.delete(); + CodePushUtils.deleteDirectoryAtPath(getCodePushPath()); } }