1.打开终端 cd至项目根目录下
2.执行命令:
react-native bundle --entry-file index.js --bundle-output ./ios/main.jsbundle --platform ios
也可将此命令在package.json中设置:
"scripts": { "iosbundle": "react-native bundle --entry-file index.js --bundle-output ./ios/main.jsbundle --platform ios",}
终端执行 npm run iosbundle 即可等同于👆
3.打开Xcode-右键Add Files To "项目名". 将生成的main.jsbundle导入至native中。
4.修改AppDelegate.m —> didFinishLaunchingWithOptions: 中代码
模拟器调试用👇
jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil];
真机用👇
jsCodeLocation = [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
至此,大功告成!!👍 👍 👍
原文请参考:https://blog.csdn.net/rainbowfactory/article/details/78990919
😘😘😘如果觉得对您有帮助,麻烦请点个❤️哦