7

I'm working on a simple photo and video capture app right now. The app successfully allows the user to take a photo or video on a button press. However, as soon as you finish taking your photo or video, it gives 2 options: "Retake" and "Use Photo" or "Use Video", depending on which one you're using.

If the user taps "Retake" then it just let's them retake a new photo or video, but when the user taps "Use photo" or "Use video" the screen freezes.

If I exit the frozen app and go look in my camera roll, the photo I just took using the app has successfully been saved. So when you tap the "Use Photo" button it does successfully save to the camera roll despite the fact that the app screen freezes.

I was told by someone that "it freezes because it takes some time to save the photo and it is running on main thread. You can use the ALAssetLibrary to fix the freezing issue."

However, I am not familiar with ALAssetLibrary or the theory of why it would be helpful in this situation. I just skimmed through some of it's documentation and I am still lost.

Any help would be greatly appreciated.

Here is the code that I have so far:

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
user3117509
  • 833
  • 3
  • 14
  • 32
  • 4
    Just a try, can you write ` [picker dismissModalViewControllerAnimated:YES];` inside the `- (void)imagePickerController:pickerController didFinishPickingMediaWithInfo:(NSDictionary *)info` I just suddenly saw that you are missing that line. – Midhun MP Dec 26 '13 at 19:23
  • 1
    That did the trick! It now saves the picture and returns the user to the main app screen as soon as they tap the "Use Photo" button. Thank you! – user3117509 Dec 26 '13 at 19:27
  • 2
    Happy to hear that, all the best :) – Midhun MP Dec 26 '13 at 19:33
  • I want the user to edit the video again or do the repicking. In didFinishPickingMediaWithInfo I do my checking and did not dismiss the Imagepicker. Buttons in the bottom are not working...any idea why? – sole007 Mar 09 '15 at 09:47

0 Answers0