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

Commit cb00cd1

Browse files
committed
use static variable instead of user prefs
1 parent 7c351e3 commit cb00cd1

File tree

1 file changed

+8
-19
lines changed

1 file changed

+8
-19
lines changed

CodePush.m

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ @implementation CodePush {
1818
static BOOL needToReportRollback = NO;
1919
static BOOL isRunningBinaryVersion = NO;
2020
static BOOL testConfigurationFlag = NO;
21+
static NSString *binaryBundleDate = nil;
2122

2223
// These constants represent valid deployment statuses
2324
static NSString *const DeploymentFailed = @"DeploymentFailed";
@@ -57,7 +58,7 @@ + (NSURL *)bundleURLForResource:(NSString *)resourceName
5758
NSError *error;
5859
NSString *packageFile = [CodePushPackage getCurrentPackageBundlePath:&error];
5960
NSURL *binaryJsBundleUrl = [[NSBundle mainBundle] URLForResource:resourceName withExtension:resourceExtension];
60-
[self saveBinaryBundleDate:binaryJsBundleUrl];
61+
[self setBinaryBundleDate:binaryJsBundleUrl];
6162

6263
NSString *logMessageFormat = @"Loading JS bundle from %@";
6364

@@ -76,10 +77,9 @@ + (NSURL *)bundleURLForResource:(NSString *)resourceName
7677
}
7778

7879
NSString *packageDate = [currentPackageMetadata objectForKey:BinaryBundleDateKey];
79-
NSString *binaryDateString = [self getBinaryBundleDateString];
8080
NSString *packageAppVersion = [currentPackageMetadata objectForKey:@"appVersion"];
8181

82-
if ([binaryDateString isEqualToString:packageDate] && ([CodePush isUsingTestConfiguration] ||[binaryAppVersion isEqualToString:packageAppVersion])) {
82+
if ([binaryBundleDate isEqualToString:packageDate] && ([CodePush isUsingTestConfiguration] ||[binaryAppVersion isEqualToString:packageAppVersion])) {
8383
// Return package file because it is newer than the app store binary's JS bundle
8484
NSURL *packageUrl = [[NSURL alloc] initFileURLWithPath:packageFile];
8585
NSLog(logMessageFormat, packageUrl);
@@ -102,17 +102,6 @@ + (NSString *)getApplicationSupportDirectory
102102
return applicationSupportDirectory;
103103
}
104104

105-
+ (NSString *)getBinaryBundleDateString
106-
{
107-
NSUserDefaults *preferences = [NSUserDefaults standardUserDefaults];
108-
NSDate *binaryBundleDate = [preferences objectForKey:BinaryBundleDateKey];
109-
if (binaryBundleDate == nil) {
110-
return nil;
111-
} else {
112-
return [NSString stringWithFormat:@"%f", [binaryBundleDate timeIntervalSince1970]];
113-
}
114-
}
115-
116105
/*
117106
* This returns a boolean value indicating whether CodePush has
118107
* been set to run under a test configuration.
@@ -122,13 +111,14 @@ + (BOOL)isUsingTestConfiguration
122111
return testConfigurationFlag;
123112
}
124113

125-
+ (void)saveBinaryBundleDate:(NSURL *)binaryJsBundleUrl
114+
/*
115+
* This caches the binary's jsbundle modified date in memory as a string.
116+
*/
117+
+ (void)setBinaryBundleDate:(NSURL *)binaryJsBundleUrl
126118
{
127119
NSDictionary *binaryFileAttributes = [[NSFileManager defaultManager] attributesOfItemAtPath:[binaryJsBundleUrl path] error:nil];
128120
NSDate *binaryDate = [binaryFileAttributes objectForKey:NSFileModificationDate];
129-
NSUserDefaults *preferences = [NSUserDefaults standardUserDefaults];
130-
[preferences setObject:binaryDate forKey:BinaryBundleDateKey];
131-
[preferences synchronize];
121+
binaryBundleDate = [NSString stringWithFormat:@"%f", [binaryDate timeIntervalSince1970]];
132122
}
133123

134124
+ (void)setDeploymentKey:(NSString *)deploymentKey
@@ -388,7 +378,6 @@ - (void)savePendingUpdate:(NSString *)packageHash
388378
{
389379
dispatch_async(dispatch_get_main_queue(), ^{
390380
NSDictionary* mutableUpdatePackage = [updatePackage mutableCopy];
391-
NSString *binaryBundleDate = [CodePush getBinaryBundleDateString];
392381
if (binaryBundleDate != nil) {
393382
[mutableUpdatePackage setValue:binaryBundleDate
394383
forKey:BinaryBundleDateKey];

0 commit comments

Comments
 (0)