Question

Is there a way to just take a photo with an iPhone?

(No delegates or controllers).

Actually what I want is:

1 One view that shows what the camera is seeing,

2) One button that takes a photo. (Like calling a function and getting the photo back)

added:The "view" above would be an area in a normal screen, also the button

Would this be the AVFoundation.

Thanks

Was it helpful?

Solution

If you're just trying to use the camera the AVFoundation framework is way overdoing it, and it's meant more for sounds and movies. The basic camera methods are all in the UIKit framework. If you're trying to edit the images, the AVFramework isn't what you need.

Also, you cannot have an app without a delegate or a controller. That's how apps are made. Without them you can't do anything. See the Apple View Controller Programming Guide for more information.

Like falconcreek said, you need to use a UIImagePickerController and set the UIImagePickerDelegate to use the camera in an app.

Question: What are you trying to do with these images that the Camera app won't work?

OTHER TIPS

Just Copy and paste follwing code into your project to get fully implemented functionality.

where takePhoto and chooseFromLibrary are my own method names which will be called on button touch. and

so make sure to referencing outlets of appropriate buttons to these methods.

Hope it will help :)

   -(IBAction)takePhoto
{
        UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];

        if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
        {
            [imagePickerController setSourceType:UIImagePickerControllerSourceTypeCamera];
        }

        // image picker needs a delegate,
        [imagePickerController setDelegate:self];

    // Place image picker on the screen
    [self presentModalViewController:imagePickerController animated:YES];
}



-(IBAction)chooseFromLibrary
{

    UIImagePickerController *imagePickerController= [[UIImagePickerController alloc]init]; 
    [imagePickerController setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];

    // image picker needs a delegate so we can respond to its messages
    [imagePickerController setDelegate:self];

    // Place image picker on the screen
    [self presentModalViewController:imagePickerController animated:YES];

}

//delegate methode will be called after picking photo either from camera or library
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{   
    [self dismissModalViewControllerAnimated:YES]; 
    UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];

    [myImageView setImage:image];    // "myImageView" name of any UImageView.
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top