Apollo
Apollo

Reputation: 9054

Preparing iOS Camera Faster

Is there a way to prep the camera any faster when presenting UIImagePickerController?

This question addresses that there is indeed a delay, as well as a way to receive a callback when the camera is ready How to know if iPhone camera is ready to take picture?

I know this must be possible (snapchat, instagram, etc) all have quite seamless UI's in terms of picture-taking.

I currently just present my imagepicker like so:

    _imagePicker = [[UIImagePickerController alloc] init];
    _imagePicker.delegate = self;
    _imagePicker.allowsEditing = YES;
    _imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
    _imagePicker.cameraFlashMode = UIImagePickerControllerCameraFlashModeOff;
    [self presentViewController:_imagePicker animated:NO completion:NULL];

Upvotes: 1

Views: 248

Answers (2)

67cherries
67cherries

Reputation: 6951

Try to setup the camera before the user tries to take a photo. As I mentioned before, this is not truly faster, but will appear so to the user.

This code will set up the camera asynchronously:

Add __block before the UIImagePickerController in _imagePicker's declaration.

NSOperationQueue *cameraSetupQueue = [[NSOperationQueue alloc] init];
cameraSetupQueue.name = @"camera setup";

[cameraSetupQueue addOperationWithBlock:^(void){

    _imagePicker = [[UIImagePickerController alloc] init];
    _imagePicker.delegate = self;
    _imagePicker.allowsEditing = YES;
    _imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
    _imagePicker.cameraFlashMode = UIImagePickerControllerCameraFlashModeOff;
}];

Put this code somewhere so that it will be executed before the camera needs to be used.

Upvotes: 0

Andrea
Andrea

Reputation: 26385

I do not think is possible, unless you start to build your own photo picker using AVFoundation and capture movies and photo from there. Build a good photo picker from scratch with the same functionalities is quite expensive task. There are some examples around, the apple AVCam is probably the most complete. You can use it as a benchmark and see how is faster than the uiimagepickercontroller

Upvotes: 1

Related Questions