经过几次尝试,我找到了如何让它与 React Native 0.52 一起工作
1 - 删除 AppDelegate.m、AppDelegate.h 和 main.m
2 - 创建一个新的 AppDelegate.swift,当它询问您是否要创建 Objective-C 桥头时,只需说“是”
3 - 将以下内容复制到 Bridging-Header.h 文件中:
#import <React/RCTBridgeModule.h>
#import <React/RCTBridge.h>
#import <React/RCTEventDispatcher.h>
#import <React/RCTRootView.h>
#import <React/RCTUtils.h>
#import <React/RCTConvert.h>
#import <React/RCTBundleURLProvider.h>
4 - 在 AppDelegate.swift 文件中使用以下代码并编辑项目名称:
@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", fallbackResource:nil)
let rootView = RCTRootView(bundleURL: jsCodeLocation, moduleName: "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
}
}
5 - 不要忘记将“YOUR-PROJECT-NAME”替换为您的实际项目名称
6 - 奔跑吧!快乐编码:)