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

Commit d114b90

Browse files
committed
use string comparison for date
1 parent e70516b commit d114b90

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

CodePush.m

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ @implementation CodePush {
2424
static NSString *const DeploymentSucceeded = @"DeploymentSucceeded";
2525

2626
// These keys represent the names we use to store data in NSUserDefaults
27+
static NSString *const BinaryBundleDateKey = @"CODE_PUSH_BINARY_DATE";
2728
static NSString *const FailedUpdatesKey = @"CODE_PUSH_FAILED_UPDATES";
2829
static NSString *const PendingUpdateKey = @"CODE_PUSH_PENDING_UPDATE";
2930

@@ -56,6 +57,11 @@ + (NSURL *)bundleURLForResource:(NSString *)resourceName
5657
NSError *error;
5758
NSString *packageFile = [CodePushPackage getCurrentPackageBundlePath:&error];
5859
NSURL *binaryJsBundleUrl = [[NSBundle mainBundle] URLForResource:resourceName withExtension:resourceExtension];
60+
NSDictionary *binaryFileAttributes = [[NSFileManager defaultManager] attributesOfItemAtPath:[binaryJsBundleUrl path] error:nil];
61+
NSDate *binaryDate = [binaryFileAttributes objectForKey:NSFileModificationDate];
62+
NSUserDefaults *preferences = [NSUserDefaults standardUserDefaults];
63+
[preferences setObject:binaryDate forKey:FailedUpdatesKey];
64+
[preferences synchronize];
5965

6066
NSString *logMessageFormat = @"Loading JS bundle from %@";
6167

@@ -65,10 +71,6 @@ + (NSURL *)bundleURLForResource:(NSString *)resourceName
6571
return binaryJsBundleUrl;
6672
}
6773

68-
NSDictionary *binaryFileAttributes = [[NSFileManager defaultManager] attributesOfItemAtPath:[binaryJsBundleUrl path] error:nil];
69-
NSDictionary *appFileAttribs = [[NSFileManager defaultManager] attributesOfItemAtPath:packageFile error:nil];
70-
NSDate *binaryDate = [binaryFileAttributes objectForKey:NSFileModificationDate];
71-
NSDate *packageDate = [appFileAttribs objectForKey:NSFileModificationDate];
7274
NSString *binaryAppVersion = [[CodePushConfig current] appVersion];
7375
NSDictionary *currentPackageMetadata = [CodePushPackage getCurrentPackage:&error];
7476
if (error || !currentPackageMetadata) {
@@ -77,9 +79,11 @@ + (NSURL *)bundleURLForResource:(NSString *)resourceName
7779
return binaryJsBundleUrl;
7880
}
7981

82+
NSString *packageDate = [currentPackageMetadata objectForKey:BinaryBundleDateKey];
83+
NSString *binaryDateString = [NSString stringWithFormat:@"%f", [binaryDate timeIntervalSince1970]];
8084
NSString *packageAppVersion = [currentPackageMetadata objectForKey:@"appVersion"];
8185

82-
if ([binaryDate compare:packageDate] == NSOrderedAscending && ([CodePush isUsingTestConfiguration] ||[binaryAppVersion isEqualToString:packageAppVersion])) {
86+
if ([binaryDateString isEqualToString:packageDate] && ([CodePush isUsingTestConfiguration] ||[binaryAppVersion isEqualToString:packageAppVersion])) {
8387
// Return package file because it is newer than the app store binary's JS bundle
8488
NSURL *packageUrl = [[NSURL alloc] initFileURLWithPath:packageFile];
8589
NSLog(logMessageFormat, packageUrl);
@@ -362,11 +366,19 @@ - (void)savePendingUpdate:(NSString *)packageHash
362366
/*
363367
* This is native-side of the RemotePackage.download method
364368
*/
365-
RCT_EXPORT_METHOD(downloadUpdate:(NSDictionary*)updatePackage
369+
RCT_EXPORT_METHOD(downloadUpdate:(NSDictionary*)immutableUpdatePackage
366370
resolver:(RCTPromiseResolveBlock)resolve
367371
rejecter:(RCTPromiseRejectBlock)reject)
368372
{
369373
dispatch_async(dispatch_get_main_queue(), ^{
374+
NSDictionary* updatePackage = [immutableUpdatePackage mutableCopy];
375+
NSUserDefaults *preferences = [NSUserDefaults standardUserDefaults];
376+
NSDate *binaryBundleDate = [preferences objectForKey:BinaryBundleDateKey];
377+
if (binaryBundleDate != nil) {
378+
[updatePackage setValue:[NSString stringWithFormat:@"%f", [binaryBundleDate timeIntervalSince1970]]
379+
forKey:BinaryBundleDateKey];
380+
}
381+
370382
[CodePushPackage downloadPackage:updatePackage
371383
// The download is progressing forward
372384
progressCallback:^(long long expectedContentLength, long long receivedContentLength) {

CodePushPackage.m

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,11 @@ + (void)downloadPackage:(NSDictionary *)updatePackage
285285
[CodePushPackage copyEntriesInFolder:unzippedFolderPath
286286
destFolder:newPackageFolderPath
287287
error:&error];
288+
if (error) {
289+
failCallback(error);
290+
return;
291+
}
292+
288293
[[NSFileManager defaultManager] removeItemAtPath:unzippedFolderPath
289294
error:&nonFailingError];
290295
if (nonFailingError) {

0 commit comments

Comments
 (0)