当我运行一个react-native项目时,我得到一个错误,没有bundle URL,但我不知道我做了什么错误,我很困惑。


当前回答

试着加上这句话:

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

其他回答

以下步骤:

用xcode打开ios文件项目 在项目包中删除main。jsbundle文件 通过main添加新的空文件。jsbundle名字 运行comment: react-native bundle——entry-file index.js——platform ios——dev false——bundle-output ios/main。Jsbundle——assets-dest ios 现在是react-native run-ios

youtube链接:https://www.youtube.com/watch?v=eCs2GsWNkoo

这是因为您的客户机无法连接到您的打包器服务器。

如果你是一个像我一样的中国程序员,我认为你可能会使用VPN通过GFW。当您的VPN工具处于“全局模式”时,您的所有请求都将通过世界旅行,无法到达本地主机

试试“自动代理模式”。

如果你不是来自中国,或者你的VPN设置已经是“自动代理模式”,我建议你关闭你的打包服务器,再试一次。

当您不允许通过localhost进行不安全连接时,或者您试图通过http接受不安全连接时,就会发生此问题。

要解决这个问题,在info.plist上添加这个:

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

...发生这种情况的另一个原因是,如果你已经安装了Visual Studio Code React Native Tools,但你一直试图在终端中使用React Native:它第一次会工作,但随后它会停止并显示红色的no bundle屏幕。

从vscode启动react native工作得很好…

在我的案例中,通过重新启动adb服务器解决了这个问题:adb kill-server && adb start-server