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

Commit 983f258

Browse files
committed
add api to specify custom NSBundle
1 parent d5e5972 commit 983f258

File tree

3 files changed

+46
-121
lines changed

3 files changed

+46
-121
lines changed

Examples/CodePushDemoApp/iOS/CodePushDemoApp.xcodeproj/project.pbxproj

Lines changed: 0 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
13B07FBD1A68108700A75B9A /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = 13B07FB11A68108700A75B9A /* LaunchScreen.xib */; };
2020
13B07FBF1A68108700A75B9A /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 13B07FB51A68108700A75B9A /* Images.xcassets */; };
2121
13B07FC11A68108700A75B9A /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 13B07FB71A68108700A75B9A /* main.m */; };
22-
140ED2AC1D01E1AD002B40FF /* libReact.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 146834041AC3E56700842450 /* libReact.a */; };
2322
146834051AC3E58100842450 /* libReact.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 146834041AC3E56700842450 /* libReact.a */; };
2423
549D09D81D528D0A00C95E36 /* libCodePush.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 549D09CD1D528CDB00C95E36 /* libCodePush.a */; };
2524
549D09DA1D528D4D00C95E36 /* libz.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = 549D09D91D528D4D00C95E36 /* libz.tbd */; };
@@ -62,13 +61,6 @@
6261
remoteGlobalIDString = 832C81801AAF6DEF007FA2F7;
6362
remoteInfo = RCTVibration;
6463
};
65-
00E356F41AD99517003FC87E /* PBXContainerItemProxy */ = {
66-
isa = PBXContainerItemProxy;
67-
containerPortal = 83CBB9F71A601CBA00E9B192 /* Project object */;
68-
proxyType = 1;
69-
remoteGlobalIDString = 13B07F861A680F5B00A75B9A;
70-
remoteInfo = CodePushDemoApp;
71-
};
7264
139105C01AF99BAD00B5F7CC /* PBXContainerItemProxy */ = {
7365
isa = PBXContainerItemProxy;
7466
containerPortal = 139105B61AF99BAD00B5F7CC /* RCTSettings.xcodeproj */;
@@ -120,7 +112,6 @@
120112
00C302BB1ABCB91800DB3ED1 /* RCTImage.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTImage.xcodeproj; path = "../node_modules/react-native/Libraries/Image/RCTImage.xcodeproj"; sourceTree = "<group>"; };
121113
00C302D31ABCB9D200DB3ED1 /* RCTNetwork.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTNetwork.xcodeproj; path = "../node_modules/react-native/Libraries/Network/RCTNetwork.xcodeproj"; sourceTree = "<group>"; };
122114
00C302DF1ABCB9EE00DB3ED1 /* RCTVibration.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTVibration.xcodeproj; path = "../node_modules/react-native/Libraries/Vibration/RCTVibration.xcodeproj"; sourceTree = "<group>"; };
123-
00E356EE1AD99517003FC87E /* CodePushDemoAppTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = CodePushDemoAppTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
124115
139105B61AF99BAD00B5F7CC /* RCTSettings.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTSettings.xcodeproj; path = "../node_modules/react-native/Libraries/Settings/RCTSettings.xcodeproj"; sourceTree = "<group>"; };
125116
139FDEE61B06529A00C62182 /* RCTWebSocket.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTWebSocket.xcodeproj; path = "../node_modules/react-native/Libraries/WebSocket/RCTWebSocket.xcodeproj"; sourceTree = "<group>"; };
126117
13B07F961A680F5B00A75B9A /* CodePushDemoApp.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = CodePushDemoApp.app; sourceTree = BUILT_PRODUCTS_DIR; };
@@ -138,14 +129,6 @@
138129
/* End PBXFileReference section */
139130

140131
/* Begin PBXFrameworksBuildPhase section */
141-
00E356EB1AD99517003FC87E /* Frameworks */ = {
142-
isa = PBXFrameworksBuildPhase;
143-
buildActionMask = 2147483647;
144-
files = (
145-
140ED2AC1D01E1AD002B40FF /* libReact.a in Frameworks */,
146-
);
147-
runOnlyForDeploymentPostprocessing = 0;
148-
};
149132
13B07F8C1A680F5B00A75B9A /* Frameworks */ = {
150133
isa = PBXFrameworksBuildPhase;
151134
buildActionMask = 2147483647;
@@ -304,32 +287,13 @@
304287
isa = PBXGroup;
305288
children = (
306289
13B07F961A680F5B00A75B9A /* CodePushDemoApp.app */,
307-
00E356EE1AD99517003FC87E /* CodePushDemoAppTests.xctest */,
308290
);
309291
name = Products;
310292
sourceTree = "<group>";
311293
};
312294
/* End PBXGroup section */
313295

314296
/* Begin PBXNativeTarget section */
315-
00E356ED1AD99517003FC87E /* CodePushDemoAppTests */ = {
316-
isa = PBXNativeTarget;
317-
buildConfigurationList = 00E357021AD99517003FC87E /* Build configuration list for PBXNativeTarget "CodePushDemoAppTests" */;
318-
buildPhases = (
319-
00E356EA1AD99517003FC87E /* Sources */,
320-
00E356EB1AD99517003FC87E /* Frameworks */,
321-
00E356EC1AD99517003FC87E /* Resources */,
322-
);
323-
buildRules = (
324-
);
325-
dependencies = (
326-
00E356F51AD99517003FC87E /* PBXTargetDependency */,
327-
);
328-
name = CodePushDemoAppTests;
329-
productName = CodePushDemoAppTests;
330-
productReference = 00E356EE1AD99517003FC87E /* CodePushDemoAppTests.xctest */;
331-
productType = "com.apple.product-type.bundle.unit-test";
332-
};
333297
13B07F861A680F5B00A75B9A /* CodePushDemoApp */ = {
334298
isa = PBXNativeTarget;
335299
buildConfigurationList = 13B07F931A680F5B00A75B9A /* Build configuration list for PBXNativeTarget "CodePushDemoApp" */;
@@ -356,12 +320,6 @@
356320
attributes = {
357321
LastUpgradeCheck = 0610;
358322
ORGANIZATIONNAME = Facebook;
359-
TargetAttributes = {
360-
00E356ED1AD99517003FC87E = {
361-
CreatedOnToolsVersion = 6.2;
362-
TestTargetID = 13B07F861A680F5B00A75B9A;
363-
};
364-
};
365323
};
366324
buildConfigurationList = 83CBB9FA1A601CBA00E9B192 /* Build configuration list for PBXProject "CodePushDemoApp" */;
367325
compatibilityVersion = "Xcode 3.2";
@@ -423,7 +381,6 @@
423381
projectRoot = "";
424382
targets = (
425383
13B07F861A680F5B00A75B9A /* CodePushDemoApp */,
426-
00E356ED1AD99517003FC87E /* CodePushDemoAppTests */,
427384
);
428385
};
429386
/* End PBXProject section */
@@ -509,13 +466,6 @@
509466
/* End PBXReferenceProxy section */
510467

511468
/* Begin PBXResourcesBuildPhase section */
512-
00E356EC1AD99517003FC87E /* Resources */ = {
513-
isa = PBXResourcesBuildPhase;
514-
buildActionMask = 2147483647;
515-
files = (
516-
);
517-
runOnlyForDeploymentPostprocessing = 0;
518-
};
519469
13B07F8E1A680F5B00A75B9A /* Resources */ = {
520470
isa = PBXResourcesBuildPhase;
521471
buildActionMask = 2147483647;
@@ -545,13 +495,6 @@
545495
/* End PBXShellScriptBuildPhase section */
546496

547497
/* Begin PBXSourcesBuildPhase section */
548-
00E356EA1AD99517003FC87E /* Sources */ = {
549-
isa = PBXSourcesBuildPhase;
550-
buildActionMask = 2147483647;
551-
files = (
552-
);
553-
runOnlyForDeploymentPostprocessing = 0;
554-
};
555498
13B07F871A680F5B00A75B9A /* Sources */ = {
556499
isa = PBXSourcesBuildPhase;
557500
buildActionMask = 2147483647;
@@ -563,14 +506,6 @@
563506
};
564507
/* End PBXSourcesBuildPhase section */
565508

566-
/* Begin PBXTargetDependency section */
567-
00E356F51AD99517003FC87E /* PBXTargetDependency */ = {
568-
isa = PBXTargetDependency;
569-
target = 13B07F861A680F5B00A75B9A /* CodePushDemoApp */;
570-
targetProxy = 00E356F41AD99517003FC87E /* PBXContainerItemProxy */;
571-
};
572-
/* End PBXTargetDependency section */
573-
574509
/* Begin PBXVariantGroup section */
575510
13B07FB11A68108700A75B9A /* LaunchScreen.xib */ = {
576511
isa = PBXVariantGroup;
@@ -584,35 +519,6 @@
584519
/* End PBXVariantGroup section */
585520

586521
/* Begin XCBuildConfiguration section */
587-
00E356F61AD99517003FC87E /* Debug */ = {
588-
isa = XCBuildConfiguration;
589-
buildSettings = {
590-
BUNDLE_LOADER = "$(TEST_HOST)";
591-
GCC_PREPROCESSOR_DEFINITIONS = (
592-
"DEBUG=1",
593-
"$(inherited)",
594-
);
595-
INFOPLIST_FILE = CodePushDemoAppTests/Info.plist;
596-
IPHONEOS_DEPLOYMENT_TARGET = 8.2;
597-
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
598-
PRODUCT_NAME = "$(TARGET_NAME)";
599-
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/CodePushDemoApp.app/CodePushDemoApp";
600-
};
601-
name = Debug;
602-
};
603-
00E356F71AD99517003FC87E /* Release */ = {
604-
isa = XCBuildConfiguration;
605-
buildSettings = {
606-
BUNDLE_LOADER = "$(TEST_HOST)";
607-
COPY_PHASE_STRIP = NO;
608-
INFOPLIST_FILE = CodePushDemoAppTests/Info.plist;
609-
IPHONEOS_DEPLOYMENT_TARGET = 8.2;
610-
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
611-
PRODUCT_NAME = "$(TARGET_NAME)";
612-
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/CodePushDemoApp.app/CodePushDemoApp";
613-
};
614-
name = Release;
615-
};
616522
13B07F941A680F5B00A75B9A /* Debug */ = {
617523
isa = XCBuildConfiguration;
618524
buildSettings = {
@@ -745,15 +651,6 @@
745651
/* End XCBuildConfiguration section */
746652

747653
/* Begin XCConfigurationList section */
748-
00E357021AD99517003FC87E /* Build configuration list for PBXNativeTarget "CodePushDemoAppTests" */ = {
749-
isa = XCConfigurationList;
750-
buildConfigurations = (
751-
00E356F61AD99517003FC87E /* Debug */,
752-
00E356F71AD99517003FC87E /* Release */,
753-
);
754-
defaultConfigurationIsVisible = 0;
755-
defaultConfigurationName = Release;
756-
};
757654
13B07F931A680F5B00A75B9A /* Build configuration list for PBXNativeTarget "CodePushDemoApp" */ = {
758655
isa = XCConfigurationList;
759656
buildConfigurations = (

ios/CodePush/CodePush.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@
2525
withExtension:(NSString *)resourceExtension
2626
subdirectory:(NSString *)resourceSubdirectory;
2727

28+
+ (NSURL *)bundleURLForResource:(NSString *)resourceName
29+
withExtension:(NSString *)resourceExtension
30+
subdirectory:(NSString *)resourceSubdirectory
31+
bundle:(NSBundle *)resourceBundle;
32+
2833
+ (NSString *)getApplicationSupportDirectory;
2934

3035
+ (NSString *)bundleAssetsPath;

ios/CodePush/CodePush.m

Lines changed: 41 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -52,24 +52,31 @@ @implementation CodePush {
5252
static BOOL needToReportRollback = NO;
5353
static BOOL testConfigurationFlag = NO;
5454

55-
// These values are used to save the bundleURL, extension and subdirectory
55+
// These values are used to save the NS bundle, name, extension and subdirectory
5656
// for the JS bundle in the binary.
57+
static NSBundle *bundleResourceBundle = nil;
5758
static NSString *bundleResourceExtension = @"jsbundle";
5859
static NSString *bundleResourceName = @"main";
5960
static NSString *bundleResourceSubdirectory = nil;
6061

62+
+ (void)initialize
63+
{
64+
// Use the mainBundle by default.
65+
bundleResourceBundle = [NSBundle mainBundle];
66+
}
67+
6168
#pragma mark - Public Obj-C API
6269

6370
+ (NSURL *)binaryBundleURL
6471
{
65-
return [[NSBundle mainBundle] URLForResource:bundleResourceName
66-
withExtension:bundleResourceExtension
67-
subdirectory:bundleResourceSubdirectory];
72+
return [bundleResourceBundle URLForResource:bundleResourceName
73+
withExtension:bundleResourceExtension
74+
subdirectory:bundleResourceSubdirectory];
6875
}
6976

7077
+ (NSString *)bundleAssetsPath
7178
{
72-
NSString *resourcePath = [[NSBundle mainBundle] resourcePath];
79+
NSString *resourcePath = [bundleResourceBundle resourcePath];
7380
if (bundleResourceSubdirectory) {
7481
resourcePath = [resourcePath stringByAppendingPathComponent:bundleResourceSubdirectory];
7582
}
@@ -79,58 +86,74 @@ + (NSString *)bundleAssetsPath
7986

8087
+ (NSURL *)bundleURL
8188
{
82-
return [self bundleURLForResource:bundleResourceName];
89+
return [self bundleURLForResource:bundleResourceName
90+
withExtension:bundleResourceExtension
91+
subdirectory:bundleResourceSubdirectory
92+
bundle:bundleResourceBundle];
8393
}
8494

8595
+ (NSURL *)bundleURLForResource:(NSString *)resourceName
8696
{
87-
bundleResourceName = resourceName;
8897
return [self bundleURLForResource:resourceName
8998
withExtension:bundleResourceExtension
90-
subdirectory:bundleResourceSubdirectory];
99+
subdirectory:bundleResourceSubdirectory
100+
bundle:bundleResourceBundle];
101+
}
102+
103+
+ (NSURL *)bundleURLForResource:(NSString *)resourceName
104+
withExtension:(NSString *)resourceExtension
105+
{
106+
return [self bundleURLForResource:resourceName
107+
withExtension:resourceExtension
108+
subdirectory:bundleResourceSubdirectory
109+
bundle:bundleResourceBundle];
91110
}
92111

93112
+ (NSURL *)bundleURLForResource:(NSString *)resourceName
94113
withExtension:(NSString *)resourceExtension
114+
subdirectory:(NSString *)resourceSubdirectory
95115
{
96116
return [self bundleURLForResource:resourceName
97117
withExtension:resourceExtension
98-
subdirectory:bundleResourceSubdirectory];
118+
subdirectory:resourceSubdirectory
119+
bundle:bundleResourceBundle];
99120
}
100121

101122
+ (NSURL *)bundleURLForResource:(NSString *)resourceName
102123
withExtension:(NSString *)resourceExtension
103124
subdirectory:(NSString *)resourceSubdirectory
125+
bundle:(NSBundle *)resourceBundle
104126
{
105127
bundleResourceName = resourceName;
106128
bundleResourceExtension = resourceExtension;
107129
bundleResourceSubdirectory = resourceSubdirectory;
108-
130+
bundleResourceBundle = resourceBundle;
131+
109132
[self ensureBinaryBundleExists];
110-
133+
111134
NSString *logMessageFormat = @"Loading JS bundle from %@";
112-
135+
113136
NSError *error;
114137
NSString *packageFile = [CodePushPackage getCurrentPackageBundlePath:&error];
115138
NSURL *binaryBundleURL = [self binaryBundleURL];
116-
139+
117140
if (error || !packageFile) {
118141
CPLog(logMessageFormat, binaryBundleURL);
119142
isRunningBinaryVersion = YES;
120143
return binaryBundleURL;
121144
}
122-
145+
123146
NSString *binaryAppVersion = [[CodePushConfig current] appVersion];
124147
NSDictionary *currentPackageMetadata = [CodePushPackage getCurrentPackage:&error];
125148
if (error || !currentPackageMetadata) {
126149
CPLog(logMessageFormat, binaryBundleURL);
127150
isRunningBinaryVersion = YES;
128151
return binaryBundleURL;
129152
}
130-
153+
131154
NSString *packageDate = [currentPackageMetadata objectForKey:BinaryBundleDateKey];
132155
NSString *packageAppVersion = [currentPackageMetadata objectForKey:AppVersionKey];
133-
156+
134157
if ([[CodePushUpdateUtils modifiedDateStringOfFileAtURL:binaryBundleURL] isEqualToString:packageDate] && ([CodePush isUsingTestConfiguration] ||[binaryAppVersion isEqualToString:packageAppVersion])) {
135158
// Return package file because it is newer than the app store binary's JS bundle
136159
NSURL *packageUrl = [[NSURL alloc] initFileURLWithPath:packageFile];
@@ -142,11 +165,11 @@ + (NSURL *)bundleURLForResource:(NSString *)resourceName
142165
#ifndef DEBUG
143166
isRelease = YES;
144167
#endif
145-
168+
146169
if (isRelease || ![binaryAppVersion isEqualToString:packageAppVersion]) {
147170
[CodePush clearUpdates];
148171
}
149-
172+
150173
CPLog(logMessageFormat, binaryBundleURL);
151174
isRunningBinaryVersion = YES;
152175
return binaryBundleURL;

0 commit comments

Comments
 (0)