Iphone如何从UIWebView访问相机?

时间:2012-05-23 11:30:20

标签: iphone objective-c ios ios5 cordova

  

可能重复:
  access camera from uiwebview?

UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;      
picker.allowsImageEditing = YES;      
picker.sourceType = UIImagePickerControllerSourceTypeCamera;       
[self presentModalViewController:picker animated:YES];
 return  NO;

我正在使用上面的编码,但它不起作用..

如何从webview打开相机 任何人帮助我。

谢谢

1 个答案:

答案 0 :(得分:3)

试试这个:

UIImagePickerController  *imgPicker = [[UIImagePickerController alloc] init];
imgPicker.delegate = self;
imgPicker.allowsImageEditing = YES;
imgPicker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentModalViewController:imgPicker animated:YES];
[imgPicker release];

以下是委托方法:

#pragma mark UIImagePickerController delegate
-(void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    // Access the uncropped image from info dictionary
    UIImage *imgCapturePhoto = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
    [self dismissModalViewControllerAnimated:YES];
}
-(void)imagePickerControllerDidCancel:(UIImagePickerController *) picker
{
    [picker dismissModalViewControllerAnimated:YES];
}

快乐编码......