【发布时间】:2021-07-26 10:48:27
【问题描述】:
我想使用您在打开相机应用程序并能够选择照片时使用的默认相机视图。之后,我想提出请求并使用 API 发送照片。这可能吗?提前感谢您的帮助!
【问题讨论】:
标签: ios swift xcode api camera
我想使用您在打开相机应用程序并能够选择照片时使用的默认相机视图。之后,我想提出请求并使用 API 发送照片。这可能吗?提前感谢您的帮助!
【问题讨论】:
标签: ios swift xcode api camera
有两种不同的控制器,一种用于相机,另一种用于照片。
对于相机,您可以使用:UIImagePickerController
从视图控制器启动相机的示例源代码:
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
[presentingViewController presentViewController:_picker animated:YES completion:nil];
//In delegate method you will receive image
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
//process your image here and do whatever you want to do
}
同样的控制器也可以用于选择图像(通过将 picker.sourceType 值指定为 UIImagePickerControllerSourceTypePhotoLibrary),从 iOS 14 引入了新的 API 来支持多个图像选择:PHImagePickerViewController。
检查此链接提供了来自苹果和 WWDC 讨论这个新 API 的示例代码:
https://developer.apple.com/documentation/photokit/selecting_photos_and_videos_in_ios
【讨论】: