@@ -18,6 +18,7 @@ @implementation CodePush {
18
18
static BOOL needToReportRollback = NO ;
19
19
static BOOL isRunningBinaryVersion = NO ;
20
20
static BOOL testConfigurationFlag = NO ;
21
+ static NSString *binaryBundleDate = nil ;
21
22
22
23
// These constants represent valid deployment statuses
23
24
static NSString *const DeploymentFailed = @" DeploymentFailed" ;
@@ -57,7 +58,7 @@ + (NSURL *)bundleURLForResource:(NSString *)resourceName
57
58
NSError *error;
58
59
NSString *packageFile = [CodePushPackage getCurrentPackageBundlePath: &error];
59
60
NSURL *binaryJsBundleUrl = [[NSBundle mainBundle ] URLForResource: resourceName withExtension: resourceExtension];
60
- [self saveBinaryBundleDate : binaryJsBundleUrl];
61
+ [self setBinaryBundleDate : binaryJsBundleUrl];
61
62
62
63
NSString *logMessageFormat = @" Loading JS bundle from %@ " ;
63
64
@@ -76,10 +77,9 @@ + (NSURL *)bundleURLForResource:(NSString *)resourceName
76
77
}
77
78
78
79
NSString *packageDate = [currentPackageMetadata objectForKey: BinaryBundleDateKey];
79
- NSString *binaryDateString = [self getBinaryBundleDateString ];
80
80
NSString *packageAppVersion = [currentPackageMetadata objectForKey: @" appVersion" ];
81
81
82
- if ([binaryDateString isEqualToString: packageDate] && ([CodePush isUsingTestConfiguration ] ||[binaryAppVersion isEqualToString: packageAppVersion])) {
82
+ if ([binaryBundleDate isEqualToString: packageDate] && ([CodePush isUsingTestConfiguration ] ||[binaryAppVersion isEqualToString: packageAppVersion])) {
83
83
// Return package file because it is newer than the app store binary's JS bundle
84
84
NSURL *packageUrl = [[NSURL alloc ] initFileURLWithPath: packageFile];
85
85
NSLog (logMessageFormat, packageUrl);
@@ -102,17 +102,6 @@ + (NSString *)getApplicationSupportDirectory
102
102
return applicationSupportDirectory;
103
103
}
104
104
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
-
116
105
/*
117
106
* This returns a boolean value indicating whether CodePush has
118
107
* been set to run under a test configuration.
@@ -122,13 +111,14 @@ + (BOOL)isUsingTestConfiguration
122
111
return testConfigurationFlag;
123
112
}
124
113
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
126
118
{
127
119
NSDictionary *binaryFileAttributes = [[NSFileManager defaultManager ] attributesOfItemAtPath: [binaryJsBundleUrl path ] error: nil ];
128
120
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 ]];
132
122
}
133
123
134
124
+ (void )setDeploymentKey : (NSString *)deploymentKey
@@ -388,7 +378,6 @@ - (void)savePendingUpdate:(NSString *)packageHash
388
378
{
389
379
dispatch_async (dispatch_get_main_queue (), ^{
390
380
NSDictionary * mutableUpdatePackage = [updatePackage mutableCopy ];
391
- NSString *binaryBundleDate = [CodePush getBinaryBundleDateString ];
392
381
if (binaryBundleDate != nil ) {
393
382
[mutableUpdatePackage setValue: binaryBundleDate
394
383
forKey: BinaryBundleDateKey];
0 commit comments