简体   繁体   English

React Native 0.66 iOS 在 AppDelegate RCTRootView init 上崩溃

[英]React Native 0.66 iOS crashes on AppDelegate RCTRootView init

I'm trying to upgrade our RN project to 0.66 (from 0.63).我正在尝试将我们的 RN 项目升级到 0.66(从 0.63)。 When I build the project in debug mode, the app crashes on startup due to uncaught exception 'NSInvalidArgumentException', reason: '-[REAEventDispatcher setBridge:]: unrecognized selector sent to instance 0x600002f51cc0' when initializing the RCTRootView in the AppDelegate.m file (entire file at the end).当我在调试模式下构建项目时,由于uncaught exception 'NSInvalidArgumentException', reason: '-[REAEventDispatcher setBridge:]: unrecognized selector sent to instance 0x600002f51cc0'AppDelegate.m文件中初始化RCTRootView时,无法识别的选择器发送到实例 0x600002f51cc0”(整个文件在最后)。

After some googling, I found the unrecognized selector bit is because some function is undefined on an object. The error is marked in the code, its about halfway through the file.经过一些谷歌搜索,我发现unrecognized selector位是因为一些 function 在 object 上未定义。代码中标记了错误,它大约在文件的一半。

I need some help finding out why this function isn't available (or what else is wrong).我需要一些帮助来找出为什么这个 function 不可用(或者还有什么问题)。 As far as I can see, the files have an implementation of the functions that are called.据我所知,这些文件具有所调用函数的实现。 Am I missing any imports?我缺少任何进口商品吗? Not that well versed in Swift, only used it in combination with React Native. Swift不是很懂,只是结合React Native用的。

I haven't made a reproducible example, but I hope someone else has come over this already in porting to this version.我还没有制作可重现的示例,但我希望其他人在移植到这个版本时已经解决了这个问题。 If you need any more information, please ask.如果您需要更多信息,请询问。 I've also attached the podfile below the relevant file.我还在相关文件下方附加了 podfile。

Appdelegate.m

#import "AppDelegate.h"

#import <React/RCTBridge.h>
#import <React/RCTBundleURLProvider.h>
#import <React/RCTRootView.h>
#import <React/RCTLinkingManager.h>

#import "RNBootSplash.h"
#import <GoogleMaps/GoogleMaps.h>

#import <UserNotifications/UserNotifications.h>
#import <RNCPushNotificationIOS.h>

#import <Firebase.h>


#ifdef FB_SONARKIT_ENABLED
#import <FlipperKit/FlipperClient.h>
#import <FlipperKitLayoutPlugin/FlipperKitLayoutPlugin.h>
#import <FlipperKitNetworkPlugin/FlipperKitNetworkPlugin.h>
#import <FlipperKitReactPlugin/FlipperKitReactPlugin.h>
#import <FlipperKitUserDefaultsPlugin/FKUserDefaultsPlugin.h>
#import <SKIOSNetworkPlugin/SKIOSNetworkAdapter.h>

static void InitializeFlipper(UIApplication *application) {
  FlipperClient *client = [FlipperClient sharedClient];
  SKDescriptorMapper *layoutDescriptorMapper =
      [[SKDescriptorMapper alloc] initWithDefaults];
  [client addPlugin:[[FlipperKitLayoutPlugin alloc]
                            initWithRootNode:application
                        withDescriptorMapper:layoutDescriptorMapper]];
  [client addPlugin:[[FKUserDefaultsPlugin alloc] initWithSuiteName:nil]];
  [client addPlugin:[FlipperKitReactPlugin new]];
  [client addPlugin:[[FlipperKitNetworkPlugin alloc]
                        initWithNetworkAdapter:[SKIOSNetworkAdapter new]]];
  [client start];
}
#endif

@implementation AppDelegate

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

  if([FIRApp defaultApp] == nil){
    [FIRApp configure];
  }

   [GMSServices provideAPIKey:@"AIzaSyC-BV0Dp46BQ1iP1HRws-oP_90FV0Aewfo"]; // add this line using the api key obtained from Google Console

#ifdef FB_SONARKIT_ENABLED
  InitializeFlipper(application);
#endif

  RCTBridge *bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions]
  //This is where the application crashes
  RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:bridge 
                                                   moduleName:@"Flatz"
                                            initialProperties:nil];
  
  if (@available(iOS 13.0, *)) {
      rootView.backgroundColor = [UIColor systemBackgroundColor];
  } else {
      rootView.backgroundColor = [[UIColor alloc] initWithRed:1.0f
                                                      green:1.0f
                                                       blue:1.0f
                                                      alpha:1];
  }

  self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
  UIViewController *rootViewController = [UIViewController new];
  rootViewController.view = rootView;
  self.window.rootViewController = rootViewController;
  [self.window makeKeyAndVisible];

  [RNBootSplash initWithStoryboard:@"LaunchScreen" rootView:rootView]; // <- initialization using the storyboard file name

  // Define UNUserNotificationCenter
    UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
    center.delegate = self;

  return YES;
}

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

// Required for the register event.
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
 [RNCPushNotificationIOS didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];
}
// Required for the notification event. You must call the completion handler after handling the remote notification.
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
{
  [RNCPushNotificationIOS didReceiveRemoteNotification:userInfo fetchCompletionHandler:completionHandler];
}
// Required for the registrationError event.
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
{
 [RNCPushNotificationIOS didFailToRegisterForRemoteNotificationsWithError:error];
}
// Required for localNotification event
- (void)userNotificationCenter:(UNUserNotificationCenter *)center
didReceiveNotificationResponse:(UNNotificationResponse *)response
         withCompletionHandler:(void (^)(void))completionHandler
{
  [RNCPushNotificationIOS didReceiveNotificationResponse:response];
}

//Called when a notification is delivered to a foreground app.
-(void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler
{
  completionHandler(UNNotificationPresentationOptionSound | UNNotificationPresentationOptionAlert | UNNotificationPresentationOptionBadge);
}


- (BOOL)application:(UIApplication *)application
   openURL:(NSURL *)url
   options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options
{
  return [RCTLinkingManager application:application openURL:url options:options];
}


- (BOOL)application:(UIApplication *)application continueUserActivity:(nonnull NSUserActivity *)userActivity
 restorationHandler:(nonnull void (^)(NSArray<id<UIUserActivityRestoring>> * _Nullable))restorationHandler
{
 return [RCTLinkingManager application:application
                  continueUserActivity:userActivity
                    restorationHandler:restorationHandler];
}

@end

Podfile

require_relative '../node_modules/react-native/scripts/react_native_pods'
require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'

platform :ios, '11.0'

target 'Flatz' do

  # No individual tracking of people or their phones
  $RNFirebaseAnalyticsWithoutAdIdSupport=true

  # React Native Maps dependencies
  rn_maps_path = '../node_modules/react-native-maps'
  pod 'react-native-google-maps', :path => rn_maps_path
  pod 'GoogleMaps'
  pod 'Google-Maps-iOS-Utils'

  config = use_native_modules!

  use_react_native!(
    :path => config["reactNativePath"],
    :hermes_enabled => true
  )


  target 'FlatzTests' do
    inherit! :complete
    # Pods for testing
  end

  # Enables Flipper.
  #
  # Note that if you have use_frameworks! enabled, Flipper will not work and
  # you should disable these next few lines.
  use_flipper!({ 'Flipper-Folly' => '2.5.3', 'Flipper' => '0.87.0', 'Flipper-RSocket' => '1.3.1' })

  post_install do |installer|
    installer.pods_project.targets.each do |target|
      target.build_configurations.each do |config|
        #1
        deployment_target = config.build_settings['IPHONEOS_DEPLOYMENT_TARGET']
          #2
          target_components = deployment_target.split
            #3
            if target_components.length > 0
              #4
              target_initial = target_components[0].to_i
                #5
                if target_initial < 9
                  config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = "9.0"
                end
            end
        end
     end

     installer.pods_project.build_configurations.each do |config|
         config.build_settings["EXCLUDED_ARCHS[sdk=iphonesimulator*]"] = "arm64"
     end
  end

   permissions_path = '../node_modules/react-native-permissions/ios'
    pod 'Permission-Camera', :path => "#{permissions_path}/Camera"
end

As jnpdx pointed out, I needed to follow the upgrade helper .正如 jnpdx 所指出的,我需要遵循upgrade helper Turns out there were quite a few steps I had missed doing it without it.事实证明,如果没有它,我错过了很多步骤。

For me I had the iOS Deployment target under build settings on 9, while on the Podfile on 11. Changing to 11 solved the problem, see how to change iOS Deployment target .对我来说,我在 9 的构建设置下有 iOS 部署目标,而在 11 的 Podfile 上。更改为 11 解决了问题,请参阅如何更改 iOS 部署目标 Also, remember to npx react-native-clean-project另外,记得 npx react-native-clean-project

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将 React Native RCTRootView 解散回 Native ViewController - Dismiss a React Native RCTRootView back to a Native ViewController 在UITableViewCell中加载React Native视图(RCTRootView) - Loading a React Native View (RCTRootView) in a UITableViewCell 将 RCTRootView 作为子视图添加到 React-Native 中的 rootViewController - Add RCTRootView as a subview to rootViewController in React-Native React Native iOS App崩溃 - React Native iOS App crashes 如何使用RCTRootView的React Native启动选项参数 - How to use React Native launch options parameter for RCTRootView 在React Native中使用nativeID /与RCTRootView子视图一起使用的正确方法是什么? - What is the correct way of using nativeID / working with RCTRootView subviews in React Native? React Native - 在AppDelegate(iOS)中将事件从Native发送到JavaScript - React Native - Sending events from Native to JavaScript in AppDelegate (iOS) React-Native Hybrid App:嵌入RCTRootView的Pop UIViewController - React-Native Hybrid App: Pop UIViewController that embeds RCTRootView -[RCTRootView cancelTouches]` 已弃用,将很快在反应原生 map 中删除 - -[RCTRootView cancelTouches]` is deprecated and will be deleted soon in react native map 为什么 React Native 视图不使用 RCTRootView 加载? - Why React Native view doesn't load using RCTRootView?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM