【问题标题】:RCTSharedApplication() delegate error react nativeRCTSharedApplication() 委托错误反应原生
【发布时间】:2017-10-12 01:46:04
【问题描述】:

所以我对 react native 和移动开发一般来说是相当新的,这个错误不断出现,失败的测试文件是 Facebook 提供的标准生成文件,带有 react native 构建。

这是测试:

- (void)testRendersWelcomeScreen
   {
  UIViewController *vc = [[[RCTSharedApplication() delegate] window] rootViewController];
  NSDate *date = [NSDate dateWithTimeIntervalSinceNow:TIMEOUT_SECONDS];
  BOOL foundElement = NO;

  __block NSString *redboxError = nil;
  RCTSetLogFunction(^(RCTLogLevel level, RCTLogSource source, NSString *fileName, NSNumber *lineNumber, NSString *message) {
    if (level >= RCTLogLevelError) {
      redboxError = message;
    }
  });

  while ([date timeIntervalSinceNow] > 0 && !foundElement && !redboxError) {
    [[NSRunLoop mainRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]];
    [[NSRunLoop mainRunLoop] runMode:NSRunLoopCommonModes beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]];

    foundElement = [self findSubviewInView:vc.view matching:^BOOL(UIView *view) {
      if ([view.accessibilityLabel isEqualToString:TEXT_TO_LOOK_FOR]) {
        return YES;
      }
      return NO;
    }];
  }

  RCTSetLogFunction(RCTDefaultLogFunction);

  XCTAssertNil(redboxError, @"RedBox error: %@", redboxError);
  XCTAssertTrue(foundElement, @"Couldn't find element with text '%@' in %d seconds", TEXT_TO_LOOK_FOR, TIMEOUT_SECONDS);
}

这是错误:

redacted/ios/ProjectTests/Project.m:40:29: error: bad receiver type 'int'
  UIViewController *vc = [[[RCTSharedApplication() delegate] window] rootViewController];

该应用程序似乎实际上可以在 iOS 模拟器中编译和工作,所以我不确定问题出在哪里,显而易见的答案可能只是删除测试。不过我对可能的原因很感兴趣,干杯。

【问题讨论】:

    标签: javascript ios objective-c facebook react-native


    【解决方案1】:

    尝试重新安装依赖项:

    $ rm -rf node_modules
    $ npm i
    

    我遇到了同样的问题,它对我有用,因为我之前在不同的分支中降级了一些库(检查:https://github.com/facebook/react-native/issues/13901)。

    【讨论】:

      猜你喜欢
      • 2018-02-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-21
      • 2022-01-16
      • 1970-01-01
      相关资源
      最近更新 更多