@@ -59,9 +59,7 @@ + (NSURL *)bundleURLForResource:(NSString *)resourceName
59
59
NSURL *binaryJsBundleUrl = [[NSBundle mainBundle ] URLForResource: resourceName withExtension: resourceExtension];
60
60
NSDictionary *binaryFileAttributes = [[NSFileManager defaultManager ] attributesOfItemAtPath: [binaryJsBundleUrl path ] error: nil ];
61
61
NSDate *binaryDate = [binaryFileAttributes objectForKey: NSFileModificationDate ];
62
- NSUserDefaults *preferences = [NSUserDefaults standardUserDefaults ];
63
- [preferences setObject: binaryDate forKey: FailedUpdatesKey];
64
- [preferences synchronize ];
62
+ [self saveBinaryBundleDate: binaryDate];
65
63
66
64
NSString *logMessageFormat = @" Loading JS bundle from %@ " ;
67
65
@@ -80,7 +78,7 @@ + (NSURL *)bundleURLForResource:(NSString *)resourceName
80
78
}
81
79
82
80
NSString *packageDate = [currentPackageMetadata objectForKey: BinaryBundleDateKey];
83
- NSString *binaryDateString = [NSString stringWithFormat: @" %f " , [binaryDate timeIntervalSince1970 ] ];
81
+ NSString *binaryDateString = [self getBinaryBundleDateString ];
84
82
NSString *packageAppVersion = [currentPackageMetadata objectForKey: @" appVersion" ];
85
83
86
84
if ([binaryDateString isEqualToString: packageDate] && ([CodePush isUsingTestConfiguration ] ||[binaryAppVersion isEqualToString: packageAppVersion])) {
@@ -106,6 +104,17 @@ + (NSString *)getApplicationSupportDirectory
106
104
return applicationSupportDirectory;
107
105
}
108
106
107
+ + (NSString *)getBinaryBundleDateString
108
+ {
109
+ NSUserDefaults *preferences = [NSUserDefaults standardUserDefaults ];
110
+ NSDate *binaryBundleDate = [preferences objectForKey: BinaryBundleDateKey];
111
+ if (binaryBundleDate == nil ) {
112
+ return nil ;
113
+ } else {
114
+ return [NSString stringWithFormat: @" %f " , [binaryBundleDate timeIntervalSince1970 ]];
115
+ }
116
+ }
117
+
109
118
/*
110
119
* This returns a boolean value indicating whether CodePush has
111
120
* been set to run under a test configuration.
@@ -115,6 +124,13 @@ + (BOOL)isUsingTestConfiguration
115
124
return testConfigurationFlag;
116
125
}
117
126
127
+ + (void )saveBinaryBundleDate : (NSDate *)binaryBundleDate
128
+ {
129
+ NSUserDefaults *preferences = [NSUserDefaults standardUserDefaults ];
130
+ [preferences setObject: binaryBundleDate forKey: BinaryBundleDateKey];
131
+ [preferences synchronize ];
132
+ }
133
+
118
134
+ (void )setDeploymentKey : (NSString *)deploymentKey
119
135
{
120
136
[CodePushConfig current ].deploymentKey = deploymentKey;
@@ -366,20 +382,19 @@ - (void)savePendingUpdate:(NSString *)packageHash
366
382
/*
367
383
* This is native-side of the RemotePackage.download method
368
384
*/
369
- RCT_EXPORT_METHOD (downloadUpdate:(NSDictionary *)immutableUpdatePackage
385
+ RCT_EXPORT_METHOD (downloadUpdate:(NSDictionary *)updatePackage
370
386
resolver:(RCTPromiseResolveBlock)resolve
371
387
rejecter:(RCTPromiseRejectBlock)reject)
372
388
{
373
389
dispatch_async (dispatch_get_main_queue (), ^{
374
- NSDictionary * updatePackage = [immutableUpdatePackage mutableCopy ];
375
- NSUserDefaults *preferences = [NSUserDefaults standardUserDefaults ];
376
- NSDate *binaryBundleDate = [preferences objectForKey: BinaryBundleDateKey];
390
+ NSDictionary * mutableUpdatePackage = [updatePackage mutableCopy ];
391
+ NSString *binaryBundleDate = [CodePush getBinaryBundleDateString ];
377
392
if (binaryBundleDate != nil ) {
378
- [updatePackage setValue: [ NSString stringWithFormat: @" %f " , [ binaryBundleDate timeIntervalSince1970 ]]
379
- forKey: BinaryBundleDateKey];
393
+ [mutableUpdatePackage setValue: binaryBundleDate
394
+ forKey: BinaryBundleDateKey];
380
395
}
381
396
382
- [CodePushPackage downloadPackage: updatePackage
397
+ [CodePushPackage downloadPackage: mutableUpdatePackage
383
398
// The download is progressing forward
384
399
progressCallback: ^(long long expectedContentLength, long long receivedContentLength) {
385
400
// Notify the script-side about the progress
@@ -393,7 +408,7 @@ - (void)savePendingUpdate:(NSString *)packageHash
393
408
// The download completed
394
409
doneCallback: ^{
395
410
NSError *err;
396
- NSDictionary *newPackage = [CodePushPackage getPackage: updatePackage [PackageHashKey] error: &err];
411
+ NSDictionary *newPackage = [CodePushPackage getPackage: mutableUpdatePackage [PackageHashKey] error: &err];
397
412
398
413
if (err) {
399
414
return reject ([NSString stringWithFormat: @" %lu " , (long )err.code], err.localizedDescription , err);
@@ -404,7 +419,7 @@ - (void)savePendingUpdate:(NSString *)packageHash
404
419
// The download failed
405
420
failCallback: ^(NSError *err) {
406
421
if ([CodePushPackage isCodePushError: err]) {
407
- [self saveFailedUpdate: updatePackage ];
422
+ [self saveFailedUpdate: mutableUpdatePackage ];
408
423
}
409
424
410
425
reject ([NSString stringWithFormat: @" %lu " , (long )err.code], err.localizedDescription , err);
0 commit comments