Quantcast
Channel: Active questions tagged react-native+ios - Stack Overflow
Viewing all articles
Browse latest Browse all 17242

Change AppDelegate.mm to AppDelegate.swift on React Native 0.71

$
0
0

I encountered the error "A moduleName is required to create an RCTROotView", and then the app was stuck on the startup page. Who can help me? thank you.

Step

  1. run 'npx react-native init RN0710RC3 --version 0.71.0-rc.3' to create a RN project
  2. create 'AppDelegate.swift''Bridging-Header.h' and delete '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 Foundationimport UIKit@UIApplicationMainclass 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;  }}

Bridging-Header.h

#import <RCTAppDelegate.h>#import <React/RCTBundleURLProvider.h>

Viewing all articles
Browse latest Browse all 17242

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>