UIImagePickerControllerSource and other such glorious Universal iOS app photo access questions
===

I'm creating a universal iOS app that gives the option of allowing users to capture and store an image with a camera. Trouble is, some iPod touches and some iPads don't have a camera. I'm wanting to insert this topmost code (which I think is correct) so my app doesn't crash with the original iPad and some iPod touches:



    if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
    {
    UIImagePickerController *picker = [[UIImagePickerController alloc] init];
    picker.sourceType = sourceType;
    picker.delegate = self;
    if(sourceType == UIImagePickerControllerSourceTypeCamera)
        [picker takePicture];
    [self presentModalViewController:picker animated:YES];
    [picker release];
    }

But where in the following code do I insert it or amend? Much obliged!


    #import "AddBrushItemViewController.h"

    @implementation AddBrushItemViewController
    @synthesize delegate, presentText, presentImage, imagePicker, presentImageFileName;



    - (void)presentPickerForPhoto {
    
    self.imagePicker.sourceType =  UIImagePickerControllerSourceTypeCamera;
    
    self.imagePicker.delegate = self;
    
    self.imagePicker.allowsEditing = NO;
    
    [self presentModalViewController:self.imagePicker animated:YES];
    }

    - (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
    {
    [picker dismissModalViewControllerAnimated:YES];
    
    UIImage *image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
    [self.presentImage setImage:image];
    
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSError *error = nil;
    NSArray *dirContents = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:documentsDirectory error:&error];
    NSString *fileName = [NSString stringWithFormat:@"photo_%i.png", [dirContents count]];
    NSString *imagePath = [documentsDirectory stringByAppendingPathComponent:fileName];
    self.presentImageFileName = [NSString stringWithFormat:fileName];
    
    NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType];   
    if ([mediaType isEqualToString:@"public.image"]){
        UIImage *editedImage = [info objectForKey:UIImagePickerControllerOriginalImage];
        NSData *webData = UIImagePNGRepresentation(editedImage);
        [webData writeToFile:imagePath atomically:YES];
    }
    }