React-native: RCTImagePickerManager requires main queue setup warning

Created on 5 Mar 2019  路  7Comments  路  Source: facebook/react-native

馃悰 Bug Report

On startup, app reports a yellow box warning:
Warning
Module RCTImagePickerManager requires main queue setup since it overrides init but doesn't implement `requiresMainQueueSetup. In a future release React Native will default to initializing all native modules on a background thread unless explocitly opted-out of.

Stack:

logIfNoNativeHook
RCTLog.js:34:8
__callFunction
MessageQueue.js:366:47
<unknown>
MessageQueue.js:106:26
(etc...)

To Reproduce

I think the use of the CameraRoll library causes the issue. Issue started appearing after an upgrade from React Native 0.57.8 -> 0.58.6.

Expected Behavior

No warning produced.

Code Example

I haven't been able to reproduce in an expo snack. But in a fresh project, I've been able to reproduce it. It requires you to manually link RNCameraRoll to the project in XCode, at which point it will generate a warning, regardless of using the library. Code example (does not produce error in Expo because it isn't linked):
https://snack.expo.io/@scarlac/rctimagepickermanager-error

Screenshot attached.
screen shot 2019-03-04 at 16 57 36

Environment

鈿★笍 react-native info

  React Native Environment Info:
    System:
      OS: macOS 10.14.3
      CPU: (12) x64 Intel(R) Core(TM) i7-8750H CPU @ 2.20GHz
      Memory: 1.98 GB / 32.00 GB
      Shell: 3.2.57 - /bin/bash
    Binaries:
      Node: 11.2.0 - ~/.nvm/versions/node/v11.2.0/bin/node
      Yarn: 1.13.0 - /usr/local/bin/yarn
      npm: 6.4.1 - ~/.nvm/versions/node/v11.2.0/bin/npm
      Watchman: 4.9.0 - /usr/local/bin/watchman
    SDKs:
      iOS SDK:
        Platforms: iOS 12.1, macOS 10.14, tvOS 12.1, watchOS 5.1
      Android SDK:
        API Levels: 23, 25, 26, 27, 28
        Build Tools: 27.0.3, 28.0.2, 28.0.3
        System Images: android-27 | Intel x86 Atom_64, android-27 | Google APIs Intel x86 Atom, android-28 | Intel x86 Atom_64, android-28 | Google APIs Intel x86 Atom_64
    IDEs:
      Android Studio: 3.2 AI-181.5540.7.32.5056338
      Xcode: 10.1/10B61 - /usr/bin/xcodebuild
    npmPackages:
      react: 16.6.3 => 16.6.3 
      react-native: 0.58.6 => 0.58.6 
    npmGlobalPackages:
      react-native-cli: 2.0.1

I looked into the source code and it seems that CameraRoll native modules indeed implement init but does not specify requiresMainQueueSetup.
Check out Libraries/CameraRoll/RCTImagePickerManager.m to see.

Bug Image Picker iOS Locked

Most helpful comment

You can add this code in RCTImagePickerManager.m

- (id)init
{
  if (self = [super init]) {
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(cameraChanged:)
                                                 name:@"AVCaptureDeviceDidStartRunningNotification"
                                               object:nil];
  }
  return self;
}

// Please add this one
+ (BOOL)requiresMainQueueSetup
{
  return NO;
}

The warning will go away

All 7 comments

Updated description with example code. Beware that Expo snack won't show warning - because it doesn't have the cameraroll lib linked. Once you link it, i'll show up.

I've seen the same warning as soon as I've added "RCTCameraRoll" to my Podfile.

Same here in RN58.6. Is there any way to get rid of this warning?

@varburg You can ignore the warning for now like this:

YellowBox.ignoreWarnings([
  // RN 0.58.6 ships with RNCameraRoll with this issue: https://github.com/facebook/react-native/issues/23755:
  'Module RCTImagePickerManager requires main queue setup since it overrides `init`',
]);

I recommend always adding a comment to these warnings so the reasoning is clear and documented. Also, you'll know to check up on it later if you specify issue link.

react native 0.59 still has this warning 馃槃

You can add this code in RCTImagePickerManager.m

- (id)init
{
  if (self = [super init]) {
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(cameraChanged:)
                                                 name:@"AVCaptureDeviceDidStartRunningNotification"
                                               object:nil];
  }
  return self;
}

// Please add this one
+ (BOOL)requiresMainQueueSetup
{
  return NO;
}

The warning will go away

react-native 0.59.3 still show this warning馃槩

Was this page helpful?
0 / 5 - 0 ratings