菜鸟教程小白 发表于 2022-12-11 18:11:55

ios - 为 ios react-native itc deploy 加载 ios/main.bundlejs 时遇到问题


                                            <p><p>我正在尝试为我的 ios 应用程序首次部署到 itc,该应用程序现在包含一个 react-nativeView 。
我使用</p>创建了包

<pre><code>react-native bundle --entry-file index.ios.js --platform ios --dev false --bundle-output ios/main.jsbundle --assets-dest ios
</code></pre>

<p>但我似乎无法弄清楚切换 jsCodeLocation 以使用新包的语法。我找到的大多数指南都在 obj-c 中,并且无法弄清楚我的命令有什么问题。当我在这里设置断点时,我发现它返回 jsCodeLocation nil。</p>

<pre><code>func loadReactNativeView () {
    //let jsCodeLocation : URL = RCTBundleURLProvider.sharedSettings().jsBundleURL(forBundleRoot: &#34;index.ios&#34;, fallbackResource: nil)

    let jsCodeLocation = Bundle.main.url(forResource: &#34;main&#34;, withExtension: &#34;jsbundle&#34;, subdirectory: &#34;ios&#34;)

    let rootView : RCTRootView = RCTRootView(bundleURL: jsCodeLocation, moduleName: &#34;HealthStorylines&#34;, initialProperties: [:], launchOptions: [:])
    rootView.backgroundColor = #colorLiteral(red: 0.2745098174, green: 0.4862745106, blue: 0.1411764771, alpha: 1)
    let frame = CGRect(x: 0, y: 0, width: self.view.bounds.width, height: self.view.bounds.height - 49)
    rootView.frame = frame
    self.view.addSubview(rootView)
}
</code></pre>

<p>非常感谢并需要有关如何调试的建议</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>我在 AppDelegate.swift 中使用这种方法。我知道答案可能会迟到,但对于其他到达这里的人来说</p>

<pre><code>func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: ?) -&gt; Bool {

let jsCodeLocation: URL = RCTBundleURLProvider.sharedSettings().jsBundleURL(forBundleRoot: &#34;index&#34;, fallbackResource:nil)
let rootView = RCTRootView(bundleURL: jsCodeLocation, moduleName: GlobalConstants.appName, initialProperties: nil, launchOptions: launchOptions)
let rootViewController = UIViewController()
rootViewController.view = rootView

self.window = UIWindow(frame: UIScreen.main.bounds)
self.window?.rootViewController = rootViewController
self.window?.makeKeyAndVisible()

return true
}
</code></pre>

<p>其中 GlobalConstants.appName 是您的应用名称为“ExampleApp”的字符串</p></p>
                                   
                                                <p style="font-size: 20px;">关于ios - 为 ios react-native itc deploy 加载 ios/main.bundlejs 时遇到问题,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/44954353/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/44954353/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - 为 ios react-native itc deploy 加载 ios/main.bundlejs 时遇到问题