An application using UIImagePickerController freezes when you select "Use Photo" after shooting

I am currently working on a simple photo and video capture application. The application successfully allows the user to take a picture or video at the touch of a button. However, as soon as you finish taking your photo or video, it gives you 2 options: Repeat and Use photo or Use video, depending on which one you are using.

If the user clicks “Retake”, then he simply allows them to re-upload a new photo or video, but when the user clicks “Use photo” or “Use video”, the screen freezes.

If I exit the frozen application and look into my camera roll, the photo that I just saved using the application has been saved. Therefore, when you click the "Use photo" button, it successfully saves in the camera roll, despite the fact that the application screen freezes.

Someone told me that "it freezes because it takes some time to save the photo and it works in the main thread. You can use ALAssetLibrary to fix the freeze problem."

However, I am not familiar with ALAssetLibrary or the theory of why this would be useful in this situation. I just looked through some of the documentation and I'm still lost.

Any help would be greatly appreciated.

Here is the code that I still have:

ViewController.h:

#import <UIKit/UIKit.h> @interface ViewController : UIViewController <UINavigationControllerDelegate, UIImagePickerControllerDelegate> @property UIImagePickerController * pickerController; -(IBAction)showCameraUI; @end 

ViewController.m:

 #import "ViewController.h" #import <MobileCoreServices/MobileCoreServices.h> @interface ViewController () <UINavigationControllerDelegate, UIImagePickerControllerDelegate> //The above are the 2 delegates required for creating a media capture/camera app. - (void)imagePickerController:pickerController didFinishPickingMediaWithInfo:(NSDictionary *)info; @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. [UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]; [UIImagePickerController availableMediaTypesForSourceType:UIImagePickerControllerSourceTypeCamera]; NSLog(@"%ld", (long)UIImagePickerControllerSourceTypeCamera); } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } -(IBAction)showCameraUI{ UIImagePickerController * pickerController = [[UIImagePickerController alloc]init]; pickerController.mediaTypes = [UIImagePickerController availableMediaTypesForSourceType:UIImagePickerControllerSourceTypeCamera]; pickerController.sourceType = UIImagePickerControllerSourceTypeCamera; pickerController.delegate = self; [self presentViewController:pickerController animated:YES completion:nil]; } - (void)imagePickerController:pickerController didFinishPickingMediaWithInfo:(NSDictionary *)info { // saves the photo you just took NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType]; if ([mediaType isEqualToString:(NSString *)kUTTypeImage]) { UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage]; UIImageWriteToSavedPhotosAlbum(image,nil,nil,nil); } } - (void)imagePickerControllerDidCancel:pickerController { [self dismissViewControllerAnimated:YES completion:nil]; } @end 
+7
ios objective-c uiimagepickercontroller alassetslibrary
source share

No one has answered this question yet.

See similar questions:

0
UIImagePickerController allows me to take photos and videos, but I don’t let me save or “use” them

or similar:

324
iOS UIImagePickerController - result of image orientation after loading
nine
IPad simulator does not work with UIImagePickerController in iPhone app
2
How do I invoke the UIImagePickerController delegate programmatically or forcefully [without user interaction]?
one
UIImagePickerController does not cancel after memory warning
0
NSLog is not running
0
UIImagePickerController removeModalViewController
0
Uploading images to the server takes forever
0
iOS: how to change between views after selecting photos?
0
UIImagePickerController allows me to take photos and videos, but I don’t let me save or “use” them
-one
UIImagePickerController Using Photo / Retake Buttons Doesn't Work

All Articles