OGeek|极客世界-中国程序员成长平台

标题: ios - 为 ios react-native itc deploy 加载 ios/main.bundlejs 时遇到问题 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-11 18:11
标题: ios - 为 ios react-native itc deploy 加载 ios/main.bundlejs 时遇到问题

我正在尝试为我的 ios 应用程序首次部署到 itc,该应用程序现在包含一个 react-native View 。 我使用

创建了包
react-native bundle --entry-file index.ios.js --platform ios --dev false --bundle-output ios/main.jsbundle --assets-dest ios

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

  func loadReactNativeView () {
    //let jsCodeLocation : URL = RCTBundleURLProvider.sharedSettings().jsBundleURL(forBundleRoot: "index.ios", fallbackResource: nil)

    let jsCodeLocation = Bundle.main.url(forResource: "main", withExtension: "jsbundle", subdirectory: "ios")

    let rootView : RCTRootView = RCTRootView(bundleURL: jsCodeLocation, moduleName: "HealthStorylines", 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)
  }

非常感谢并需要有关如何调试的建议



Best Answer-推荐答案


我在 AppDelegate.swift 中使用这种方法。我知道答案可能会迟到,但对于其他到达这里的人来说

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {

  let jsCodeLocation: URL = RCTBundleURLProvider.sharedSettings().jsBundleURL(forBundleRoot: "index", 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
}

其中 GlobalConstants.appName 是您的应用名称为“ExampleApp”的字符串

关于ios - 为 ios react-native itc deploy 加载 ios/main.bundlejs 时遇到问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44954353/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4