如何使用phonegap应用程序访问iPhone的相机

时间:2011-06-16 10:09:39

标签: iphone cordova

我有一个为Android开发的简单应用程序,它可以拍照,访问设备的相机。 我希望在iPhone上运行相同的应用程序。对于android,我们写入访问清单文件中的相机的权限。如何在iPhone中访问相机。我们需要在哪里设置它。有人可以帮帮我吗?

提前致谢

2 个答案:

答案 0 :(得分:3)

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

答案 1 :(得分:0)

要在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];

如有任何困难,请告诉我。

以下是相机的委托方法。

委托名称:UIImagePickerControllerDelegate,UINavigationControllerDelegate

方法:

#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];

}

干杯