我正在使用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/

10-13 07:43
查看更多