简体   繁体   English

如何使用phonegap应用程序访问iPhone的摄像头

[英]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. 我有一个为android开发的简单应用程序,它可以拍照,访问设备的相机。 I want the same application to be run on iPhone. 我希望在iPhone上运行相同的应用程序。 For android we write permissions for accessing camera in manifest file. 对于android,我们在清单文件中写入访问摄像头的权限。 How do you access the camera in iPhone. 如何在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. 要在iPhone中访问相机,可以使用以下代码。

// 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 委托名称: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 干杯

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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