views:

395

answers:

1

Hi Everyone:

I have found a lot of information on using UIImagePickerController to let the user choose the image they want from the Photos application's data. I am wondering how I can create this same effect on 3.0, as it doesn't seem as if a lot of the old code works anymore. In addition, I would like the user to be able to take a new picture from this same pop-up.

Thanks for any help!

A: 

Works in 3.0, same as before; I don't believe there were any changes. I just alloc/init a UIImagePickerController, and pass it to presentModalViewController, like this:

- (void) chooseImageFromLibrary {
    if( ![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary] ) return;

    UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
    imagePickerController.delegate = self;
    imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    imagePickerController.allowsImageEditing = YES;
    [self presentModalViewController:imagePickerController animated:YES];
}

- (void) chooseImageFromCamera {
    if( ![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera] ) return;

    UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
    imagePickerController.delegate = self;
    imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
    imagePickerController.allowsImageEditing = YES;
    [self presentModalViewController:imagePickerController animated:YES];
}

Implement the delegate methods, too:

- (void)imagePickerController:(UIImagePickerController *)picker 
     didFinishPickingImage:(UIImage *)image 
         editingInfo:(NSDictionary *)editingInfo {
    // Do something with the image here.

    [[picker parentViewController] dismissModalViewControllerAnimated:YES];
}

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
    [[picker parentViewController] dismissModalViewControllerAnimated:YES];
}
zpasternack
Hi zpasternack: What would my .h file look like for these functions... What would the class have to conform to?
PF1