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

Commit d43b18b

Browse files
committed
Checking for null binary bundle
1 parent dfc2222 commit d43b18b

File tree

1 file changed

+35
-2
lines changed

1 file changed

+35
-2
lines changed

ios/CodePush/CodePush.m

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,15 @@ + (NSURL *)bundleURLForResource:(NSString *)resourceName
7575
{
7676
bundleResourceName = resourceName;
7777
bundleResourceExtension = resourceExtension;
78+
79+
[self ensureBinaryBundleExists];
80+
81+
NSString *logMessageFormat = @"Loading JS bundle from %@";
82+
7883
NSError *error;
7984
NSString *packageFile = [CodePushPackage getCurrentPackageBundlePath:&error];
8085
NSURL *binaryBundleURL = [self binaryBundleURL];
8186

82-
NSString *logMessageFormat = @"Loading JS bundle from %@";
83-
8487
if (error || !packageFile) {
8588
NSLog(logMessageFormat, binaryBundleURL);
8689
isRunningBinaryVersion = YES;
@@ -190,6 +193,36 @@ - (void)dealloc
190193
[[NSNotificationCenter defaultCenter] removeObserver:self];
191194
}
192195

196+
/*
197+
* This method ensures that the app was packaged with a JS bundle
198+
* file, and if not, it throws the appropriate exception.
199+
*/
200+
+ (void)ensureBinaryBundleExists
201+
{
202+
if (![self binaryBundleURL]) {
203+
NSString *errorMessage;
204+
205+
#if TARGET_IPHONE_SIMULATOR
206+
errorMessage = @"React Native doesn't generate your app's JS bundle by default when deploying to the simulator. "
207+
"If you'd like to test CodePush using the simulator, you can do one of three things depending on your React "
208+
"Native version and/or preferred workflow:\n\n"
209+
210+
"1. Update your AppDelegate.m file to load the JS bundle from the packager instead of from CodePush. "
211+
"You can still test your CodePush update experience using this workflow (debug builds only).\n\n"
212+
213+
"2. Force the JS bundle to be generated in simulator builds by removing the if block which echoes "
214+
"\"Skipping bundling for Simulator platform\" in the \"node_modules/react-native/packager/react-native-xcode.sh\" file.\n\n"
215+
216+
"3. Deploy a release build to the simulator, which unlike debug builds, will generate the JS bundle (React Native >=0.22.0 only).";
217+
#else
218+
errorMessage = = [NSString stringWithFormat:@"The specified JS bundle file wasn't found within the app's binary. Is \"%@\" the correct file name?", [bundleResourceName stringByAppendingPathExtension:bundleResourceExtension]];
219+
#endif
220+
221+
RCTFatal([NSError errorWithDomain:@"CodePushError" code:-1
222+
userInfo:@{ NSLocalizedDescriptionKey: NSLocalizedString(errorMessage, nil) }]);
223+
}
224+
}
225+
193226
- (instancetype)init
194227
{
195228
self = [super init];

0 commit comments

Comments
 (0)