oscarsales opened a new issue #703:
URL: https://github.com/apache/cordova-plugin-camera/issues/703


   # Feature Request
   
   I've created this post as a **feature request** although it's a bug because 
this is a well known bug of this plugin, and the solution is also known, so 
should have been solved long time ago. If you google it you can find some posts 
about it on stackoverflow and github.
   
   What I'm requesting is a new version of the plugin with this fix.
   
   ## Feature Description
   
   When you open the picker in iOS (gallery or camera) the first time it takes 
A LOT of time to open, in my case around 15 seconds. This happens because the 
native code opens the picker **outside** the UI thread. When it opens you can 
find the console flooded with these warnings:
   
   `Main Thread Checker: UI API called on a background thread.`
   
   
   ## Motivation Behind Feature
   
   I found some people complaining about this and waiting for a solution. In my 
case, I develop apps for clients who report this problem to me. Furthermore I 
work with more people in a repository, so every time someone downloads the 
project the plugin is reinstalled and the error persists. For now I fixed it 
with the workaround below, but this is just a temporary solution, we've had 
this fix for months, waiting for this plugin to publish a new version with this 
error fixed.
   
   I imagine that the devs who manage this plugin are busy with other issues 
before launching a new version and I guess this problem must be already queued, 
I understand. However this is a priority, not to me but because the iOS version 
is not usable. Without this fix, this plugin for iOS is useless.
   
   ## Alternatives or Workarounds
   
   As answered in [this 
topic](https://stackoverflow.com/questions/58038810/xcode-10-main-thread-checker-cordova-camera-plugin),
 the solution is very easy:
   
   CDVCamera.m, line 186, method **showCameraPicker**(),
   move the first lines into the "dispatch_async" block:
   
   ```
   - (void)showCameraPicker:(NSString*)callbackId 
withOptions:(CDVPictureOptions *) pictureOptions
   {
        /////// IT WAS HERE
   
       // Perform UI operations on the main thread
       dispatch_async(dispatch_get_main_queue(), ^{
           
           //////// <----- NOW HERE
           CDVCameraPicker* cameraPicker = [CDVCameraPicker 
createFromPictureOptions:pictureOptions];
           self.pickerController = cameraPicker;
   
           cameraPicker.delegate = self;
           cameraPicker.callbackId = callbackId;
           cameraPicker.webView = self.webView;
           //////// 
   ```
   
   With this simple change it works correctly and the alert in the console 
disappears.
   
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to