我正在使用 UIImagePicker 向用户展示照片,以便用户可以选择要在我的应用中使用的图像。
我的问题是,在用户第一次打开图像选择器时,他们会看到一条提示:“我的应用程序”想要访问您的照片,其中有两个选项,不允许和确定。
我的要求是,当用户单击“不允许”时,图像选择器将被关闭。
有没有办法检测到用户选择了不允许?
目前它给用户留下了一个丑陋的空白模态视图。如果用户再次打开图像选择器,他们将显示漂亮的苹果提供的消息,内容为“此应用无法访问您的照片等”
这里是我如何使用图像选择器:
self.imagePickerController = [[UIImagePickerController alloc] init];
self.imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentModalViewController:self.imagePickerController animated:YES];
最佳答案
知道了!
if ([ALAssetsLibrary authorizationStatus] == ALAuthorizationStatusNotDetermined) {
ALAssetsLibrary *assetsLibrary = [[ALAssetsLibrary alloc] init];
[assetsLibrary enumerateGroupsWithTypes:ALAssetsGroupAll usingBlock:^(ALAssetsGroup *group, BOOL *stop) {
if (*stop) {
// INSERT CODE TO PERFORM WHEN USER TAPS OK eg. :
return;
}
*stop = TRUE;
} failureBlock:^(NSError *error) {
// INSERT CODE TO PERFORM WHEN USER TAPS DONT ALLOW, eg. :
self.imagePickerController dismissViewControllerAnimated:YES completion:nil];
}];
}
关于iphone - Objective-C - 如何检测用户是否单击了“不允许访问照片”按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14742578/