【问题标题】:iPhone:Can my program access Camera using imagepicker API?iPhone:我的程序可以使用 imagepicker API 访问相机吗?
【发布时间】:2010-12-17 14:28:34
【问题描述】:

如果我的程序想要访问相机并拍照并使用 UIImagePicker (UIImagePickerControllerSourceTypeCamera) 返回应用程序的功能,我的程序可以在 iPhone 上执行此操作,尤其是在非越狱设备上吗? Apple 是否允许在 AppStore 中上传此类程序? 如果我们创建这样的程序,我在某处看到 Apple 不允许这样做(从 3rd 方应用程序访问相机)。是这样吗?

感谢您的建议。

谢谢。

-普拉巴卡尔。

【问题讨论】:

标签: iphone


【解决方案1】:

你直接使用UIImagePickerController

UIImagePickerController *thePicker = [[UIImagePickerController alloc] init];
thePicker.delegate = thePickerDelegate;
thePicker.sourceType = UIImagePickerControllerSourceTypeCamera;

//Here you would present thePicker modally, and release it after this
//It will be deallocated when you remove it from screen
[anotherViewController presentModalViewController: thePicker animated:NO];
[thePicker release];

thePickerDelegate中,实现

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo;

image 是您拍摄的照片,您可以随意操作它。如果您希望UIImagePickerController 在拍摄一张照片后消失,您可以在此处触发此操作,并将其从屏幕上移除,在上述模态案例中,通过调用

[thePicker dismissModalViewControllerAnimated: NO];

【讨论】:

  • 谢谢。如果我们离开“thePicker”,这不是泄漏吗?
  • 如果我们把它放在哪里?请说明您认为哪里有泄漏。
  • 如果我们像下面这样分配,我们需要在哪里释放“thePicker”?我可以在“didFinishPickingImage”的末尾释放它吗? UIImagePickerController *thePicker = [[UIImagePickerController alloc] init];
  • 哦,我明白了,好吧,我没有写整个显示选择器 - 释放选择器部分,因为你可能想将它添加到导航控制器,标签栏,作为一个孩子另一个视图,或模态显示。当然,你应该在以一种或另一种方式将它添加到屏幕后释放它。
  • 我已经编辑了我的答案以包括模式表示和选择器的删除。
猜你喜欢
  • 1970-01-01
  • 2011-02-06
  • 1970-01-01
  • 2011-02-08
  • 1970-01-01
  • 2011-12-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多