我有一个原生iOS应用程序,我们使用react-native来嵌入Facebook风格的社交Feed.要在调试模式下运行,我使用打包服务器和以下代码:
NSURL *jsCodeLocation = [NSURL URLWithString:@"http://X.X.X.X:8081/index.ios.bundle?platform=ios"];
bridgeReactView = [[RCTBridge alloc] initWithBundleURL: jsCodeLocation
moduleProvider: nil
launchOptions:nil];
rootReactView = [[RCTRootView alloc] initWithBridge:bridgeReactView
moduleName:@"SocialFeed"
initialProperties:@{}];
Run Code Online (Sandbox Code Playgroud)
其中XXXX是我的本地IP地址.这工作正常,但我无法将反应代码捆绑到发布版本中.从官方文档和其他Stack Overflow帖子我收集到,最初需要手动捆绑代码
react-native bundle --entry-file="index.ios.js" --bundle-output="./ios/MyApp/main.jsbundle' --dev=false --platform='ios' --assets-dest="./ios"
Run Code Online (Sandbox Code Playgroud)
并将上面的jsCodeLocation定义更改为
*jsCodeLocation = [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
Run Code Online (Sandbox Code Playgroud)
显然,在更新版本的react-native中,如果选择发布版本配置,xCode会自动为您捆绑代码,在这种情况下,您必须将上面的内容更改为
NSURL *jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index.ios" fallbackResource:nil];
Run Code Online (Sandbox Code Playgroud)
这些方法都不适用于我们 - 在两种情况下jsCodeLocation都设置为nil,并且我得到"No bundle URL present"错误:
2017-05-08 15:06:56.738 [fatal][tid:main] No bundle URL present.
Make sure you're running a packager server or have included a .jsbundle file in your application bundle.
Run Code Online (Sandbox Code Playgroud)
顺便说一句,我已经尝试在Info.plist文件中设置以下值:
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
<key>NSAllowsArbitraryLoadsInWebContent</key>
<true/>
<key>NSAllowsLocalNetworking</key>
<true/>
</dict>
</key>
Run Code Online (Sandbox Code Playgroud)
小智 13
您应该执行以下操作:
react-native bundle --dev false --platform ios --entry-file index.ios.js --bundle-output ios/main.jsbundle --assets-dest ./ios注意:您只需要第一次运行第2步.