Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIImagePickerController will not initialize camera view sometimes

When I instantiate and present an UIImagePickerController, sometimes it will take up to 5 seconds for the video feed to show up and there will just be a black screen. I do instantiate the UIImagePickerController multiple times from different views. What could be the source of this problem?

like image 905
coolio Avatar asked Nov 04 '22 16:11

coolio


1 Answers

Delays on UI stuff are usualy related to code not being ran on Main Thread. Only Main Thread can change the UI, so if your code happens to run on some other background thread it will have a few seconds delay. You can guarantee a block of code will be ran on Main Thread with:

dispatch_async(dispatch_get_main_queue(), ^{
    // Your code
});

I've answered a similar problem here:

dismissViewControllerAnimated:completion: has a couple second delay

like image 61
manecosta Avatar answered Nov 15 '22 07:11

manecosta