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

Commit e5ec7fd

Browse files
committed
feedback
1 parent d114b90 commit e5ec7fd

File tree

1 file changed

+28
-13
lines changed

1 file changed

+28
-13
lines changed

CodePush.m

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,7 @@ + (NSURL *)bundleURLForResource:(NSString *)resourceName
5959
NSURL *binaryJsBundleUrl = [[NSBundle mainBundle] URLForResource:resourceName withExtension:resourceExtension];
6060
NSDictionary *binaryFileAttributes = [[NSFileManager defaultManager] attributesOfItemAtPath:[binaryJsBundleUrl path] error:nil];
6161
NSDate *binaryDate = [binaryFileAttributes objectForKey:NSFileModificationDate];
62-
NSUserDefaults *preferences = [NSUserDefaults standardUserDefaults];
63-
[preferences setObject:binaryDate forKey:FailedUpdatesKey];
64-
[preferences synchronize];
62+
[self saveBinaryBundleDate:binaryDate];
6563

6664
NSString *logMessageFormat = @"Loading JS bundle from %@";
6765

@@ -80,7 +78,7 @@ + (NSURL *)bundleURLForResource:(NSString *)resourceName
8078
}
8179

8280
NSString *packageDate = [currentPackageMetadata objectForKey:BinaryBundleDateKey];
83-
NSString *binaryDateString = [NSString stringWithFormat:@"%f", [binaryDate timeIntervalSince1970]];
81+
NSString *binaryDateString = [self getBinaryBundleDateString];
8482
NSString *packageAppVersion = [currentPackageMetadata objectForKey:@"appVersion"];
8583

8684
if ([binaryDateString isEqualToString:packageDate] && ([CodePush isUsingTestConfiguration] ||[binaryAppVersion isEqualToString:packageAppVersion])) {
@@ -106,6 +104,17 @@ + (NSString *)getApplicationSupportDirectory
106104
return applicationSupportDirectory;
107105
}
108106

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+
109118
/*
110119
* This returns a boolean value indicating whether CodePush has
111120
* been set to run under a test configuration.
@@ -115,6 +124,13 @@ + (BOOL)isUsingTestConfiguration
115124
return testConfigurationFlag;
116125
}
117126

127+
+ (void)saveBinaryBundleDate:(NSDate *)binaryBundleDate
128+
{
129+
NSUserDefaults *preferences = [NSUserDefaults standardUserDefaults];
130+
[preferences setObject:binaryBundleDate forKey:BinaryBundleDateKey];
131+
[preferences synchronize];
132+
}
133+
118134
+ (void)setDeploymentKey:(NSString *)deploymentKey
119135
{
120136
[CodePushConfig current].deploymentKey = deploymentKey;
@@ -366,20 +382,19 @@ - (void)savePendingUpdate:(NSString *)packageHash
366382
/*
367383
* This is native-side of the RemotePackage.download method
368384
*/
369-
RCT_EXPORT_METHOD(downloadUpdate:(NSDictionary*)immutableUpdatePackage
385+
RCT_EXPORT_METHOD(downloadUpdate:(NSDictionary*)updatePackage
370386
resolver:(RCTPromiseResolveBlock)resolve
371387
rejecter:(RCTPromiseRejectBlock)reject)
372388
{
373389
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];
377392
if (binaryBundleDate != nil) {
378-
[updatePackage setValue:[NSString stringWithFormat:@"%f", [binaryBundleDate timeIntervalSince1970]]
379-
forKey:BinaryBundleDateKey];
393+
[mutableUpdatePackage setValue:binaryBundleDate
394+
forKey:BinaryBundleDateKey];
380395
}
381396

382-
[CodePushPackage downloadPackage:updatePackage
397+
[CodePushPackage downloadPackage:mutableUpdatePackage
383398
// The download is progressing forward
384399
progressCallback:^(long long expectedContentLength, long long receivedContentLength) {
385400
// Notify the script-side about the progress
@@ -393,7 +408,7 @@ - (void)savePendingUpdate:(NSString *)packageHash
393408
// The download completed
394409
doneCallback:^{
395410
NSError *err;
396-
NSDictionary *newPackage = [CodePushPackage getPackage:updatePackage[PackageHashKey] error:&err];
411+
NSDictionary *newPackage = [CodePushPackage getPackage:mutableUpdatePackage[PackageHashKey] error:&err];
397412

398413
if (err) {
399414
return reject([NSString stringWithFormat: @"%lu", (long)err.code], err.localizedDescription, err);
@@ -404,7 +419,7 @@ - (void)savePendingUpdate:(NSString *)packageHash
404419
// The download failed
405420
failCallback:^(NSError *err) {
406421
if ([CodePushPackage isCodePushError:err]) {
407-
[self saveFailedUpdate:updatePackage];
422+
[self saveFailedUpdate:mutableUpdatePackage];
408423
}
409424

410425
reject([NSString stringWithFormat: @"%lu", (long)err.code], err.localizedDescription, err);

0 commit comments

Comments
 (0)