【发布时间】:2016-10-14 11:35:32
【问题描述】:
感谢阅读。
iOS 9.3.3 版本遇到一个新问题,第一次使用 UIImagePickerController 访问相机时。
默认情况下,Apple 在 iOS 应用程序中首次访问相机时会显示权限警报,它可以正常工作。
拍照并点击使用按钮后,Apple 会显示另一个带有消息的警报视图 - “应用程序想要访问照片”。
点击确定按钮,我没有得到选定的照片。这只是第一次发生。但在其他版本中不会发生。
我知道这无法避免 iOS 的警报视图。但是拍照后有没有可能抑制第二个警报视图。
有人可以帮我吗?
请看以下代码:
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.mediaTypes = [UIImagePickerController availableMediaTypesForSourceType:UIImagePickerControllerSourceTypeCamera];
imagePickerController.delegate = self;
imagePickerController.allowsEditing = NO;
imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
[weakSelf.parent presentViewController:imagePickerController animated:YES completion:nil];
} else {
UIAlertController *alert = [UIAlertController
alertControllerWithTitle:@"Camera is not available."
message:nil
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *okAction = [UIAlertAction
actionWithTitle:@"Ok"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction *action)
{
}];
[alert addAction:okAction];
[self.parent presentViewController:alert animated:YES completion:nil];
}
[self.parent presentViewController:importMenu animated:YES completion:nil];
【问题讨论】:
-
可以添加picker的代码吗?
-
当您第一次尝试访问相机或照片库时,iOS 会显示警报视图。您是否将选择器的 sourceType 设置为其他任何地方的库?
-
两个警报都不同,一个用于相机访问,另一个用于照片。您可以通过同时询问用户两个权限来避免这种情况
-
@Mahesh 试试我的答案。这是为了在未经许可的情况下访问画廊
-
[self.parent presentViewController:importMenu animated:YES completion:nil];是什么?您尝试在呈现的视图控制器(即图像选择器)上呈现的 importMenu 是什么?
标签: ios objective-c xcode