在React Native0.71上将AppDelegate.mm更改为AppDelegate.swift

332nm8kg  于 2023-02-13  发布在  React
关注(0)|答案(1)|浏览(195)

我遇到了错误"创建RCTROOTView需要一个moduleName",然后应用卡在了启动页面,谁能帮我?谢谢。

    • 步骤**

1.运行"npx react-native init RN0.71.0RC3--版本0.71.0-rc.3"以创建RN项目
1.创建"应用程序委托. swift""桥接标头. h"并删除"应用程序委托. mm""应用程序委托. h""main. m"

    • 应用代理. mm**
#import "AppDelegate.h"

#import <React/RCTBundleURLProvider.h>

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{

    self.moduleName = @"RN0710RC3";
    return [super application:application didFinishLaunchingWithOptions:launchOptions];
}

- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
{
    #if DEBUG
    return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index"];
    #else
    return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
    #endif
}

- (BOOL)concurrentRootEnabled
{
    return true;
}

@end
    • 应用代理. swift**
import Foundation
import UIKit

@UIApplicationMain
class AppDelegate: RCTAppDelegate {

  func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
      CommonTheme.currentTheme.primaryColor = .red;
      self.moduleName = "RN0710RC3";
      return self.application(application, didFinishLaunchingWithOptions: launchOptions);
  }

  override func sourceURL(for bridge: RCTBridge!) -> URL! {
      #if DEBUG
      return RCTBundleURLProvider.sharedSettings()?.jsBundleURL(forBundleRoot: "index", fallbackResource: nil)
      #else
      return Bundle.main.url(forResource: "main", withExtension: "jsBundle")
      #endif
  }

  func concurrentRootEnabled() -> Bool {
      return true;
  }
}
    • 桥接-集管. h**
#import <RCTAppDelegate.h>
#import <React/RCTBundleURLProvider.h>
jq6vz3qz

jq6vz3qz1#

函数concurrentRootEnabled是Objective-C接口RCTAppDelegate所必需的,因此您应该将@objc放入其中。

@objc func concurrentRootEnabled() -> Bool {
   return true;
}

相关问题