Xcode 10 Main Thread Checker: Cordova Camera Plugin

↘锁芯ラ 提交于 2021-02-10 05:31:47

问题


Following iOS13 release, I'm testing a hybrid app using Cordova. Launching the camera is very slow and generates the following:

=================================================================

Main Thread Checker: UI API called on a background thread: -[UIImagePickerController init]

PID: 1347, TID: 618928, Thread name: (none), Queue name: com.apple.root.default-qos, QoS: 0

Backtrace:

4 0x0000000100f1bba0 +[CDVCameraPicker createFromPictureOptions:] + 124

5 0x0000000100f15d54 -[CDVCamera showCameraPicker:withOptions:] + 108

6 0x0000000100f15570 __25-[CDVCamera takePicture:]_block_invoke_2 + 336

7 AVFoundation 0x00000001b76178f8 2BC0C357-314E-3AE8-B006-C28528B87512 + 710904

8 TCC 0x00000001b35dfbf8 85A762AF-99DB-3B4C-B24B-09600CC17196 + 7160

9 TCC 0x00000001b35e3de4 85A762AF-99DB-3B4C-B24B-09600CC17196 + 24036

10 libxpc.dylib 0x00000001acfe3804 79A1F1AD-9CB4-3334-91D9-E1ED6B1032A3 + 104452

11 libxpc.dylib 0x00000001acfd72c4 79A1F1AD-9CB4-3334-91D9-E1ED6B1032A3 + 53956

12 libdispatch.dylib 0x000000010109b3b4 _dispatch_client_callout3 + 20

13 libdispatch.dylib 0x00000001010b7000 _dispatch_mach_msg_async_reply_invoke + 392

14 libdispatch.dylib 0x00000001010ada8c _dispatch_kevent_worker_thread + 1436

15 libsystem_pthread.dylib 0x00000001ad0e6adc _pthread_wqthread + 336

16 libsystem_pthread.dylib 0x00000001ad0ecc7c start_wqthread + 8

Xcode 10.3 cordova-plugin-camera version 4.1.0

running on iPhone X, iOS13

Eventually the camera opens and allows me to take a photo but the UI is not displayed correctly afterwards. I've tried creating a brand new app with only the camera plugin added and the same thing happens.

How this can be resolved?


回答1:


It would seem that UIImagePickerController needs to be called in the UI Thread. Fortunately, the code is already ready for that change!

Just move the cameraPicker init section into the main thread section:

dispatch_async(dispatch_get_main_queue(), ^{
  // UI MainThread execution
 CDVCameraPicker* cameraPicker = [CDVCameraPicker createFromPictureOptions:pictureOptions];
 weakSelf.pickerController = cameraPicker;

cameraPicker.delegate = weakSelf;
cameraPicker.callbackId = command.callbackId;
// we need to capture this state for memory warnings that dealloc this object
cameraPicker.webView = weakSelf.webView;
  ...
}

D.



来源:https://stackoverflow.com/questions/58038810/xcode-10-main-thread-checker-cordova-camera-plugin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!