question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

🍏 Thread 8: -[UIImagePickerController init] must be used from main thread only

See original GitHub issue

Bug

Having an issue with iOS and initializing the react-native-image-picker. On init. the module lags for ~5 sec. before the camera is launched.

Debug output in XCode:

=================================================================
Main Thread Checker: UI API called on a background thread: -[UIImagePickerController init]
PID: 9819, TID: 2519723, Thread name: (none), Queue name: com.facebook.react.ImagePickerManagerQueue, QoS: 0
Backtrace:
4   caudex                              0x00000001017b0e58 -[ImagePickerManager launchImagePicker:] + 96
5   caudex                              0x00000001017b0de0 -[ImagePickerManager launchImagePicker:options:] + 116
6   caudex                              0x00000001017af27c -[ImagePickerManager launchImageLibrary:callback:] + 140
7   CoreFoundation                      0x00000001b39b4c20 7519E999-1053-3367-B9D5-8844F6D3BDC6 + 1252384
8   CoreFoundation                      0x00000001b3884d30 7519E999-1053-3367-B9D5-8844F6D3BDC6 + 7472
9   CoreFoundation                      0x00000001b3885908 7519E999-1053-3367-B9D5-8844F6D3BDC6 + 10504
10  caudex                              0x0000000101291ed0 -[RCTModuleMethod invokeWithBridge:module:arguments:] + 1896
11  caudex                              0x00000001012958cc _ZN8facebook5reactL11invokeInnerEP9RCTBridgeP13RCTModuleDatajRKN5folly7dynamicE + 660
12  caudex                              0x0000000101295440 _ZZN8facebook5react15RCTNativeModule6invokeEjON5folly7dynamicEiENK3$_0clEv + 144
13  caudex                              0x00000001012953a4 ___ZN8facebook5react15RCTNativeModule6invokeEjON5folly7dynamicEi_block_invoke + 28
14  libdispatch.dylib                   0x0000000104cf97fc _dispatch_call_block_and_release + 24
15  libdispatch.dylib                   0x0000000104cfabd8 _dispatch_client_callout + 16
16  libdispatch.dylib                   0x0000000104d01b48 _dispatch_lane_serial_drain + 744
17  libdispatch.dylib                   0x0000000104d026e4 _dispatch_lane_invoke + 448
18  libdispatch.dylib                   0x0000000104d0dadc _dispatch_workloop_worker_thread + 1324
19  libsystem_pthread.dylib             0x00000001b36cab88 _pthread_wqthread + 276
20  libsystem_pthread.dylib             0x00000001b36cd760 start_wqthread + 8
2020-02-24 08:24:12.923320+0100 caudex[9819:2519723] [reports] Main Thread Checker: UI API called on a background thread: -[UIImagePickerController init]
PID: 9819, TID: 2519723, Thread name: (none), Queue name: com.facebook.react.ImagePickerManagerQueue, QoS: 0
Backtrace:
4   caudex                              0x00000001017b0e58 -[ImagePickerManager launchImagePicker:] + 96
5   caudex                              0x00000001017b0de0 -[ImagePickerManager launchImagePicker:options:] + 116
6   caudex                              0x00000001017af27c -[ImagePickerManager launchImageLibrary:callback:] + 140
7   CoreFoundation                      0x00000001b39b4c20 7519E999-1053-3367-B9D5-8844F6D3BDC6 + 1252384
8   CoreFoundation                      0x00000001b3884d30 7519E999-1053-3367-B9D5-8844F6D3BDC6 + 7472
9   CoreFoundation                      0x00000001b3885908 7519E999-1053-3367-B9D5-8844F6D3BDC6 + 10504
10  caudex                              0x0000000101291ed0 -[RCTModuleMethod invokeWithBridge:module:arguments:] + 1896
11  caudex                              0x00000001012958cc _ZN8facebook5reactL11invokeInnerEP9RCTBridgeP13RCTModuleDatajRKN5folly7dynamicE + 660
12  caudex                              0x0000000101295440 _ZZN8facebook5react15RCTNativeModule6invokeEjON5folly7dynamicEiENK3$_0clEv + 144
13  caudex                              0x00000001012953a4 ___ZN8facebook5react15RCTNativeModule6invokeEjON5folly7dynamicEi_block_invoke + 28
14  libdispatch.dylib                   0x0000000104cf97fc _dispatch_call_block_and_release + 24
15  libdispatch.dylib                   0x0000000104cfabd8 _dispatch_client_callout + 16
16  libdispatch.dylib                   0x0000000104d01b48 _dispatch_lane_serial_drain + 744
17  libdispatch.dylib                   0x0000000104d026e4 _dispatch_lane_invoke + 448
18  libdispatch.dylib                   0x0000000104d0dadc _dispatch_workloop_worker_thread + 1324
19  libsystem_pthread.dylib             0x00000001b36cab88 _pthread_wqthread + 276
20  libsystem_pthread.dylib             0x00000001b36cd760 start_wqthread + 8
bilde

Environment info

React native info output:

System:
    OS: macOS 10.15.3
    CPU: (12) x64 Intel(R) Core(TM) i7-8750H CPU @ 2.20GHz
    Memory: 120.71 MB / 16.00 GB
    Shell: 5.7.1 - /bin/zsh
  Binaries:
    Node: 11.10.1 - ~/.nvm/versions/node/v11.10.1/bin/node
    Yarn: 1.22.0 - /usr/local/bin/yarn
    npm: 6.7.0 - ~/.nvm/versions/node/v11.10.1/bin/npm
    Watchman: 4.9.0 - /usr/local/bin/watchman
  SDKs:
    iOS SDK:
      Platforms: iOS 13.2, DriverKit 19.0, macOS 10.15, tvOS 13.2, watchOS 6.1
  IDEs:
    Android Studio: 3.5 AI-191.8026.42.35.6010548
    Xcode: 11.3.1/11C504 - /usr/bin/xcodebuild
  npmPackages:
    react: 16.9.0 => 16.9.0 
    react-native: 0.61.5 => 0.61.5

Library version: 2.3.0

Steps To Reproduce

This is how I launch it:

   ImagePicker.launchImageLibrary(options, (response) => {
    ...
    });

I used the the built-in-functionality Main Thread Checker

Describe what you expected to happen:

  1. Expect the module to be launched immediately

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:9

github_iconTop GitHub Comments

3reactions
xclidongbocommented, Mar 5, 2020

Please change it like this:

- (void)launchImagePicker:(RNImagePickerTarget)target options:(NSDictionary *)options
{
    self.options = options;
    dispatch_async(dispatch_get_main_queue(), ^(void) {
       [self launchImagePicker:target];
    });
}
0reactions
stale[bot]commented, Jul 18, 2020

Closing this issue after a prolonged period of inactivity. Fell free to reopen this issue, if this still affecting you.

Read more comments on GitHub >

github_iconTop Results From Across the Web

UIImagePickerController init] must be used from main thread ...
Having an issue with iOS and initializing the react-native-image-picker. On init. the module lags for ~5 sec. before the camera is launched.
Read more >
Xcode UIView.init(frame:) must be used from main thread only
I'm trying to render some views in background thread to not affect the main thread. That was never a problem before Xcode 9....
Read more >
`-[UIView initWithFrame:] must be used from main thread only ...
It's there just as a NSObject. Even some may say that `UIView` needs to be in main thread to obtain its life cycle....
Read more >
Xcode UIView.init(frame:) must be used from main thread only
iOS : Xcode UIView. init (frame:) must be used from main thread only [ Gift : Animated Search Engine : https://bit.ly/AnimSearch ] iOS...
Read more >
Seeing error "[UIView init] must be used from main thread only"
systemFont(ofSize: 18, weight: .bold) 8. label.numberOfLines = 0 9. return label 10. }() 11. 12. var stackView : UIStackView = { 13. var ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found