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

Commit 2705e42

Browse files
committed
Merge pull request #38 from qingfeng/patch-1
When main.jsbundle newer than app.jsbundle time, load main.jsbundle
2 parents a1626b9 + 8d11499 commit 2705e42

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

CodePush.m

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,26 @@ + (NSURL *)getBundleUrl
2727
{
2828
NSError *error;
2929
NSString *packageFolder = [CodePushPackage getCurrentPackageFolderPath:&error];
30+
NSURL *binaryJsBundleUrl = [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
3031

3132
if (error || !packageFolder)
3233
{
33-
return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
34+
return binaryJsBundleUrl;
3435
}
3536

3637
NSString *packageFile = [packageFolder stringByAppendingPathComponent:UpdateBundleFileName];
37-
return [[NSURL alloc] initFileURLWithPath:packageFile];
38+
39+
NSDictionary *binaryFileAttributes = [[NSFileManager defaultManager] attributesOfItemAtPath:[binaryJsBundleUrl path] error:nil];
40+
NSDictionary *appFileAttribs = [[NSFileManager defaultManager] attributesOfItemAtPath:packageFile error:nil];
41+
NSDate *binaryDate = [binaryFileAttributes objectForKey:NSFileModificationDate];
42+
NSDate *packageDate = [appFileAttribs objectForKey:NSFileModificationDate];
43+
44+
if ([binaryDate compare:packageDate] == NSOrderedAscending) {
45+
// Return package file because it is newer than the app store binary's JS bundle
46+
return [[NSURL alloc] initFileURLWithPath:packageFile];
47+
} else {
48+
return binaryJsBundleUrl;
49+
}
3850
}
3951

4052
// Internal API methods

0 commit comments

Comments
 (0)