2

我正在开发一个包含 MongoDB Stitch 和 React-Native 的 iOS 项目。MongoDB API 是用 Swift 编写的,而 React Native iOS Structure 是基于 Objective-C 的。所以我决定将 Objective-C 项目转换为 Swift,以便我可以使用 MongoDB 的 Swift API 并通过 RCTBridge 与 React Native 进行通信。所以我将项目转换为 Swift,但是当我在 Xcode 中编译它时,它显示一个空白屏幕。我创建了 AppDelegate.swift 和 ProjectName-Bridging-Header.h 文件。

我正在使用 React Native 版本 0.59.5

我在 AppDelegate.swift 文件中使用了这段代码

import Foundation

import UIKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
  var window: UIWindow?
  var bridge: RCTBridge!

  func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    let jsCodeLocation: URL

    jsCodeLocation = RCTBundleURLProvider.sharedSettings().jsBundleURL(forBundleRoot: "index.ios", fallbackResource:nil)
    let rootView = RCTRootView(bundleURL: jsCodeLocation, moduleName: "REPLACE_WITH_YOUR_PROJECT_NAME", 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
  }
}
4

0 回答 0