【问题标题】:Change AppDelegate.mm to AppDelegate.swift on React Native 0.71在 React Native 0.71 上将 AppDelegate.mm 更改为 AppDelegate.swift
【发布时间】:2023-02-10 12:06:13
【问题描述】:

我遇到错误“A moduleName is required to create an RCTROotView”,然后应用程序卡在启动页面上。谁能帮我?谢谢。

  1. 运行'npx react-native init RN0710RC3 --version 0.71.0-rc.3'创建一个RN项目
  2. 创建“AppDelegate.swift”“Bridging-Header.h”并删除“AppDelegate.mm”“AppDelegate.h”“main.m”

    AppDelegate.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
    

    AppDelegate.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>
    

【问题讨论】:

    标签: ios react-native swift5


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 2023-02-21
      • 2022-10-13
      • 2023-02-11
      • 1970-01-01
      • 1970-01-01
      • 2023-02-09
      • 1970-01-01
      • 2017-01-31
      • 1970-01-01
      相关资源
      最近更新 更多