简体   繁体   中英

How to access camera of iPhone using phonegap app

I have a simple application developed for android which takes a photo, accessing the camera of device. I want the same application to be run on iPhone. For android we write permissions for accessing camera in manifest file. How do you access the camera in iPhone. Where do we need to set up it. Can anyone please help me?

Thanks in advance

使用最新代码中的Media Capture API,或等待0.9.6: http : //docs.phonegap.com/phonegap_media_capture_capture.md.html

For accessing the camera in iPhone, you can use following code.

// Camera

UIImagePickerController *imgPicker = [[UIImagePickerController alloc] init];

imgPicker.delegate = self;

imgPicker.allowsImageEditing = YES;

imgPicker.sourceType = UIImagePickerControllerSourceTypeCamera;

//[self presentModalViewController:imgPicker animated:YES];

[objParent presentModalViewController:imgPicker animated:YES];

[imgPicker release];

Let me know in case of any difficulty.

Below are the delegate method for camera.

Delegate Name: UIImagePickerControllerDelegate, UINavigationControllerDelegate

Methods:

#pragma mark UIImagePickerController delegate

-(void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info

{

    // Access the uncropped image from info dictionary

    UIImage *imgCapturePhoto = [info objectForKey:@"UIImagePickerControllerOriginalImage"];

    [imgPhoto setImage:imgCapturePhoto];

    [self dismissModalViewControllerAnimated:YES];
}

-(void)imagePickerControllerDidCancel:(UIImagePickerController *) picker

{

    [picker dismissModalViewControllerAnimated:YES];

}

Cheers

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM