@@ -24,6 +24,7 @@ @implementation CodePush {
24
24
static NSString *const DeploymentSucceeded = @" DeploymentSucceeded" ;
25
25
26
26
// These keys represent the names we use to store data in NSUserDefaults
27
+ static NSString *const BinaryBundleDateKey = @" CODE_PUSH_BINARY_DATE" ;
27
28
static NSString *const FailedUpdatesKey = @" CODE_PUSH_FAILED_UPDATES" ;
28
29
static NSString *const PendingUpdateKey = @" CODE_PUSH_PENDING_UPDATE" ;
29
30
@@ -56,6 +57,11 @@ + (NSURL *)bundleURLForResource:(NSString *)resourceName
56
57
NSError *error;
57
58
NSString *packageFile = [CodePushPackage getCurrentPackageBundlePath: &error];
58
59
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 ];
59
65
60
66
NSString *logMessageFormat = @" Loading JS bundle from %@ " ;
61
67
@@ -65,10 +71,6 @@ + (NSURL *)bundleURLForResource:(NSString *)resourceName
65
71
return binaryJsBundleUrl;
66
72
}
67
73
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 ];
72
74
NSString *binaryAppVersion = [[CodePushConfig current ] appVersion ];
73
75
NSDictionary *currentPackageMetadata = [CodePushPackage getCurrentPackage: &error];
74
76
if (error || !currentPackageMetadata) {
@@ -77,9 +79,11 @@ + (NSURL *)bundleURLForResource:(NSString *)resourceName
77
79
return binaryJsBundleUrl;
78
80
}
79
81
82
+ NSString *packageDate = [currentPackageMetadata objectForKey: BinaryBundleDateKey];
83
+ NSString *binaryDateString = [NSString stringWithFormat: @" %f " , [binaryDate timeIntervalSince1970 ]];
80
84
NSString *packageAppVersion = [currentPackageMetadata objectForKey: @" appVersion" ];
81
85
82
- if ([binaryDate compare : packageDate] == NSOrderedAscending && ([CodePush isUsingTestConfiguration ] ||[binaryAppVersion isEqualToString: packageAppVersion])) {
86
+ if ([binaryDateString isEqualToString : packageDate] && ([CodePush isUsingTestConfiguration ] ||[binaryAppVersion isEqualToString: packageAppVersion])) {
83
87
// Return package file because it is newer than the app store binary's JS bundle
84
88
NSURL *packageUrl = [[NSURL alloc ] initFileURLWithPath: packageFile];
85
89
NSLog (logMessageFormat, packageUrl);
@@ -362,11 +366,19 @@ - (void)savePendingUpdate:(NSString *)packageHash
362
366
/*
363
367
* This is native-side of the RemotePackage.download method
364
368
*/
365
- RCT_EXPORT_METHOD (downloadUpdate:(NSDictionary *)updatePackage
369
+ RCT_EXPORT_METHOD (downloadUpdate:(NSDictionary *)immutableUpdatePackage
366
370
resolver:(RCTPromiseResolveBlock)resolve
367
371
rejecter:(RCTPromiseRejectBlock)reject)
368
372
{
369
373
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
+
370
382
[CodePushPackage downloadPackage: updatePackage
371
383
// The download is progressing forward
372
384
progressCallback: ^(long long expectedContentLength, long long receivedContentLength) {
0 commit comments