UIImagePickerController is very slow when calling alloc init

I have a view controller that displays when I click on one of the tabs in the tabBarController. In this view of the controller, I initialize the UIImagePickerController in the viewDidLoad method:

- (void)viewDidLoad { [super viewDidLoad]; //Set imagePicker //-------------------------// _imagePicker = [[UIImagePickerController alloc] init]; _imagePicker.delegate = self; _imagePicker.videoMaximumDuration = 10.0f; } 

The goal is then to display the UIImagePickerController later when the button is pressed. For some reason, although when you click the tab icon for this view controller, it hangs for 3-4 seconds while this viewDidLoad method is running. When I comment on the line _imagePicker = [[UIImagePickerController alloc] init], there is no response time, and the view controller loads immediately - as it should be.

Does anyone know why allocating and initializing a UIImagePickerController takes so much time? If so, is there a way to speed it up besides running it as a background process? This seems to be abnormal behavior.

I am using iOS7 and I am not calling viewWillAppear or viewDidAppear.

+6
source share
3 answers

It turns out that this is a problem only in debug mode (when the iPhone is connected and works through Xcode). When the same application runs without connecting to Xcode, lag does not occur.

+16
source

try it

 //show a HUD or activityIndicator dispatch_async(dispatch_queue_create("openPhotosCamera", NULL), ^{ UIImagePickerController *mediaUI = [[UIImagePickerController alloc] init]; dispatch_async(dispatch_get_main_queue(), ^{ //hide HUD or activityIndicator [presenter presentViewController:mediaUI animated:YES completion:nil]; }); }); 

** presenter - your viewController / self

+3
source

Try it.

  - (void)viewDidLoad{ //Set imagePicker //-------------------------// _imagePicker = [[UIImagePickerController alloc] init]; _imagePicker.delegate = self; _imagePicker.videoMaximumDuration = 10.0f; [super viewDidLoad]; 
-1
source

Source: https://habr.com/ru/post/959245/


All Articles