“不存在捆绑包网址"React-native iOS发布模式出现错误 [英] "No bundle url present" error with react-native iOS release mode

查看:95
本文介绍了“不存在捆绑包网址"React-native iOS发布模式出现错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个本地iOS应用,我们正在使用react-native嵌入一个Facebook风格的社交供稿.要在调试模式下运行,我使用打包器服务器和以下代码:

I have a native iOS app, and we're using react-native to embed a Facebook-style social feed. To run in debug mode I use the packager server and the following code:

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:@{}];

其中X.X.X.X是我的本地IP地址.这可以正常工作,但是我无法将React代码捆绑到发行版本中.从官方文档和其他Stack Overflow帖子中,我了解到,最初必须手动将代码与类似的东西捆绑在一起

where X.X.X.X is my local IP address. This works fine, but I can't get it to bundle the react code into the release version. From the official docs and other Stack Overflow posts I've gathered that it was originally necessary to manually bundle the code with something like

react-native bundle --entry-file="index.ios.js" --bundle-output="./ios/MyApp/main.jsbundle' --dev=false --platform='ios' --assets-dest="./ios"

并将上面的jsCodeLocation定义更改为

and change the jsCodeLocation definition above to

*jsCodeLocation = [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];

显然,在最新版本的react-native中,如果您选择发布版本配置,则xCode会自动为您捆绑代码,在这种情况下,您必须将以上代码更改为

Apparently, in more recent versions of react-native, xCode will bundle the code for you automatically if you choose the release build configuration, in which case you must change the above to

NSURL *jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index.ios" fallbackResource:nil];

这两种方法都不适合我们-在两种情况下jsCodeLocation都设置为nil,并且出现无捆绑包网址"错误:

Neither of these methods work for us - in both cases jsCodeLocation gets set to nil, and I get the "No bundle URL present" error:

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.

偶然地,我尝试在Info.plist文件中设置以下值:

Incidentally, I have tried setting the following values in my Info.plist file:

<key>NSAppTransportSecurity</key>
    <dict>
        <key>NSAllowsArbitraryLoads</key>
        <true/>
        <key>NSAllowsArbitraryLoadsInWebContent</key>
        <true/>
        <key>NSAllowsLocalNetworking</key>
        <true/>
    </dict>
</key>

推荐答案

您应该执行以下操作:

  1. 运行以下命令: react-native bundle --dev false --platform ios --entry-file index.ios.js --bundle-output ios/main.jsbundle --assets-dest ./ios
  2. 通过将main.jsbundle和资产目录拖动到项目中,将它们添加到xcode.

注意:您只需要在第一时间运行步骤2.

Note: You only have to run step 2 the first time.

这篇关于“不存在捆绑包网址"React-native iOS发布模式出现错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆