First step: Export JS bundle and picture Resources
Unlike the packaged react Native Android app, we can't export react Native iOS apps with the command step. We need to package the JS part of the code with the image resource, and then add it to the iOS project through Xcode.
command to Export JS bundle
Under the root directory of the React native project:
1 |
react-native bundle --entry-file index.ios.js --platform ios --dev false --bundle-output release_ios/main.jsbundle --assets-dest release_ios/ |
With the above command, we can export the JS part of the Code and picture resources, such as packaging exported to the Release_ios directory:
Generate Jsbundle
Among them, assets for the project in the JS part of the image resources (not including the original module of the picture resources), Main.jsbundle is the JS part of the code.
Before we execute the package command, we need to make sure that we have the Release_ios folder at the root of our project and create one without it.
Step two: Import JS bundle and picture resources into iOS project
In this step we need to use Xcode, select the Assets folder and the Main.jsbundle file to drag it to the Xcode project navigation panel.
Import Jsbundle
Then, modify the APPDELEGATE.M file and add the following code:
12345678910 |
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSURL *jsCodeLocation;
//jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index.ios" fallbackResource:nil];
+jsCodeLocation = [[NSBundle mainBundle] URLForResource:@
"main"
withExtension:@
"jsbundle"
];
#endif
...
return
YES;
}
|
The function of the above code is to let react native to use the jsbundle we just imported, so we have been freed from the reliance on the local NODEJS server.
Tip: If you use the Codepush hot update in your project, then we need to be able to read the local jsbundle directly through Codepush, as follows:
1234567891011 |
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSURL *jsCodeLocation;
#ifdef DEBUG
jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@
"index.ios"
fallbackResource:nil];
#else
jsCodeLocation = [CodePush bundleURL];
#endif
...
return
YES;
}
|
So far, we've imported JS bundle and image resources into our iOS project, and then we're ready to publish our iOS app.
Step three: Publish iOS apps
。。。
Original link
React native release app packaged iOS app