@@ -18,7 +18,6 @@ @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 ;
22
21
23
22
// These constants represent valid deployment statuses
24
23
static NSString *const DeploymentFailed = @" DeploymentFailed" ;
@@ -39,26 +38,39 @@ @implementation CodePush {
39
38
static NSString *const PackageHashKey = @" packageHash" ;
40
39
static NSString *const PackageIsPendingKey = @" isPending" ;
41
40
41
+ // These values are used to save the bundleURL and extension for the JS bundle
42
+ // in the binary.
43
+ static NSString *binaryJsName = @" main" ;
44
+ static NSString *binaryJsExtension = @" jsbundle" ;
45
+
46
+
42
47
#pragma mark - Public Obj-C API
43
48
49
+ + (NSURL *)binaryJsBundleUrl
50
+ {
51
+ return [[NSBundle mainBundle ] URLForResource: binaryJsName withExtension: binaryJsExtension];
52
+ }
53
+
44
54
+ (NSURL *)bundleURL
45
55
{
46
- return [self bundleURLForResource: @" main " ];
56
+ return [self bundleURLForResource: binaryJsName ];
47
57
}
48
58
49
59
+ (NSURL *)bundleURLForResource : (NSString *)resourceName
50
60
{
61
+ binaryJsName = resourceName;
51
62
return [self bundleURLForResource: resourceName
52
- withExtension: @" jsbundle " ];
63
+ withExtension: binaryJsExtension ];
53
64
}
54
65
55
66
+ (NSURL *)bundleURLForResource : (NSString *)resourceName
56
67
withExtension : (NSString *)resourceExtension
57
68
{
69
+ binaryJsName = resourceName;
70
+ binaryJsExtension = resourceExtension;
58
71
NSError *error;
59
72
NSString *packageFile = [CodePushPackage getCurrentPackageBundlePath: &error];
60
- NSURL *binaryJsBundleUrl = [[NSBundle mainBundle ] URLForResource: resourceName withExtension: resourceExtension];
61
- [self setBinaryBundleDate: binaryJsBundleUrl];
73
+ NSURL *binaryJsBundleUrl = [self binaryJsBundleUrl ];
62
74
63
75
NSString *logMessageFormat = @" Loading JS bundle from %@ " ;
64
76
@@ -79,7 +91,7 @@ + (NSURL *)bundleURLForResource:(NSString *)resourceName
79
91
NSString *packageDate = [currentPackageMetadata objectForKey: BinaryBundleDateKey];
80
92
NSString *packageAppVersion = [currentPackageMetadata objectForKey: @" appVersion" ];
81
93
82
- if ([binaryBundleDate isEqualToString: packageDate] && ([CodePush isUsingTestConfiguration ] ||[binaryAppVersion isEqualToString: packageAppVersion])) {
94
+ if ([[ self modifiedDateStringFromFileUrl: binaryJsBundleUrl] isEqualToString: packageDate] && ([CodePush isUsingTestConfiguration ] ||[binaryAppVersion isEqualToString: packageAppVersion])) {
83
95
// Return package file because it is newer than the app store binary's JS bundle
84
96
NSURL *packageUrl = [[NSURL alloc ] initFileURLWithPath: packageFile];
85
97
NSLog (logMessageFormat, packageUrl);
@@ -112,13 +124,17 @@ + (BOOL)isUsingTestConfiguration
112
124
}
113
125
114
126
/*
115
- * This caches the binary's jsbundle modified date in memory as a string.
127
+ * This returns the modified date as a string for a given file URL .
116
128
*/
117
- + (void ) setBinaryBundleDate : (NSURL *)binaryJsBundleUrl
129
+ + (NSString *) modifiedDateStringFromFileUrl : (NSURL *)fileUrl
118
130
{
119
- NSDictionary *binaryFileAttributes = [[NSFileManager defaultManager ] attributesOfItemAtPath: [binaryJsBundleUrl path ] error: nil ];
120
- NSDate *binaryDate = [binaryFileAttributes objectForKey: NSFileModificationDate ];
121
- binaryBundleDate = [NSString stringWithFormat: @" %f " , [binaryDate timeIntervalSince1970 ]];
131
+ if (fileUrl != nil ) {
132
+ NSDictionary *fileAttributes = [[NSFileManager defaultManager ] attributesOfItemAtPath: [fileUrl path ] error: nil ];
133
+ NSDate *modifiedDate = [fileAttributes objectForKey: NSFileModificationDate ];
134
+ return [NSString stringWithFormat: @" %f " , [modifiedDate timeIntervalSince1970 ]];
135
+ } else {
136
+ return nil ;
137
+ }
122
138
}
123
139
124
140
+ (void )setDeploymentKey : (NSString *)deploymentKey
@@ -377,9 +393,10 @@ - (void)savePendingUpdate:(NSString *)packageHash
377
393
rejecter:(RCTPromiseRejectBlock)reject)
378
394
{
379
395
dispatch_async (dispatch_get_main_queue (), ^{
380
- NSDictionary * mutableUpdatePackage = [updatePackage mutableCopy ];
381
- if (binaryBundleDate != nil ) {
382
- [mutableUpdatePackage setValue: binaryBundleDate
396
+ NSDictionary *mutableUpdatePackage = [updatePackage mutableCopy ];
397
+ NSURL *binaryJsBundleUrl = [CodePush binaryJsBundleUrl ];
398
+ if (binaryJsBundleUrl != nil ) {
399
+ [mutableUpdatePackage setValue: [CodePush modifiedDateStringFromFileUrl: binaryJsBundleUrl]
383
400
forKey: BinaryBundleDateKey];
384
401
}
385
402
0 commit comments