简体   繁体   中英

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM