We have an ionic 3 application that uses a camera and gallery to select images. I am showing an action sheet and the user can select either gallery or camera to select an image.
When trying to open the camera in the app, It takes a long time to ask for permission and start capturing the image. In the meantime app just freezes. And after capturing the image, the status bar disappears. It throws the following stack trace;
Main Thread Checker: UI API called on a background thread: -[UIImagePickerController init]
PID: 3140, TID: 1450459, Thread name: (none), Queue name: com.apple.root.default-qos, QoS: 0
Backtrace:
4 ManyTutors 0x00000001027a87a4 +[CDVCameraPicker createFromPictureOptions:] + 112
5 ManyTutors 0x00000001027a2d1c __25-[CDVCamera takePicture:]_block_invoke + 1148
6 libdispatch.dylib 0x00000001030c3bcc _dispatch_call_block_and_release + 32
7 libdispatch.dylib 0x00000001030c56c0 _dispatch_client_callout + 20
8 libdispatch.dylib 0x00000001030c80ec _dispatch_queue_override_invoke + 952
9 libdispatch.dylib 0x00000001030d8ae0 _dispatch_root_queue_drain + 364
10 libdispatch.dylib 0x00000001030d9488 _dispatch_worker_thread2 + 140
11 libsystem_pthread.dylib 0x00000001f6dbb7c8 _pthread_wqthread + 216
12 libsystem_pthread.dylib 0x00000001f6dc275c start_wqthread + 8
2021-01-11 17:13:01.703428+0800 ManyTutors[3140:1450459] [reports] Main Thread Checker: UI API called on a background thread: -[UIImagePickerController init]
PID: 3140, TID: 1450459, Thread name: (none), Queue name: com.apple.root.default-qos, QoS: 0
Backtrace:
4 ManyTutors 0x00000001027a87a4 +[CDVCameraPicker createFromPictureOptions:] + 112
5 ManyTutors 0x00000001027a2d1c __25-[CDVCamera takePicture:]_block_invoke + 1148
6 libdispatch.dylib 0x00000001030c3bcc _dispatch_call_block_and_release + 32
7 libdispatch.dylib 0x00000001030c56c0 _dispatch_client_callout + 20
8 libdispatch.dylib 0x00000001030c80ec _dispatch_queue_override_invoke + 952
9 libdispatch.dylib 0x00000001030d8ae0 _dispatch_root_queue_drain + 364
10 libdispatch.dylib 0x00000001030d9488 _dispatch_worker_thread2 + 140
11 libsystem_pthread.dylib 0x00000001f6dbb7c8 _pthread_wqthread + 216
12 libsystem_pthread.dylib 0x00000001f6dc275c start_wqthread + 8
[Camera] Failed to read exposureBiasesByMode dictionary: Error Domain=NSCocoaErrorDomain Code=4864 "* -[NSKeyedUnarchiver _initForReadingFromData:error:throwLegacyExceptions:]: data is NULL" UserInfo={NSDebugDescription=* -[NSKeyedUnarchiver _initForReadingFromData:error:throwLegacyExceptions:]: data is NULL}
When I select a camera for the first time, it should ask permission right away, and after giving the permission it should take a photo and use that photo in the app.
When I click on the camera for the first time, It takes more than 2 minutes to show the permission dialog and after clicking the picture when we come back to the app, the app header disappears and the app starts lagging and doesn't work properly.
I only face this issue in IOS apps. Android works fine. For IOS, I have tested it on an emulator, on a real device in debugging mode, and also by uploading it to test flight.
cli packages: (C:\nvm\v10.15.1\node_modules)
@ionic/cli-utils : 1.19.2
ionic (Ionic CLI) : 3.20.0
global packages:
cordova (Cordova CLI) : not installed
local packages:
@ionic/app-scripts : 3.2.4
Cordova Platforms : android 7.0.0 ios 5.0.1
Ionic Framework : ionic-angular 3.9.10
System:
Android SDK Tools : 26.1.1
Node : v10.15.1
npm : 6.4.1
OS : Windows 10
Versions:
Xcode Version : 12
IOS Version : 14
Any Suggestion will be appreciated.
The slowness problem is answered in this post.
You need to edit src/ios/CDVCamera.m
to move a block of code, as described in the other post.
see also the mess at this GitHub issue, where no one is merging the fix.