Ios UIImagePicker isSourceTypeAvailable在库为空时返回YES

Ios UIImagePicker isSourceTypeAvailable在库为空时返回YES,ios,uiimagepickercontroller,Ios,Uiimagepickercontroller,正在与UIImagePicker进行斗争。我试图捕获一个空库,以防止用户被发送到那里 这里是我检查相机或库是否可用并包含内容的地方: imagePicker = [[UIImagePickerController alloc]init]; imagePicker.modalPresentationStyle = UIModalPresentationCurrentContext; [[imagePicker navigationBar] setTintColor:nil]; //set the

正在与UIImagePicker进行斗争。我试图捕获一个空库,以防止用户被发送到那里

这里是我检查相机或库是否可用并包含内容的地方:

imagePicker = [[UIImagePickerController alloc]init];
imagePicker.modalPresentationStyle = UIModalPresentationCurrentContext;
[[imagePicker navigationBar] setTintColor:nil];

//set the delegate
imagePicker.delegate = self;

//Determine if a camera is available and react accordingly
BOOL cameraAvailable = [UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera];
BOOL libraryAvailable = [UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary];
if (cameraAvailable) {
    if(cameraAvailable && libraryAvailable) {
        UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@""
                                                                 delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil
                                                        otherButtonTitles:@"Take Photo With Camera", @"Select Photo From Library", nil];
        actionSheet.actionSheetStyle = UIActionSheetStyleAutomatic;
        [actionSheet showInView:self.view];
    } else {
        UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@""
                                                                 delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil
                                                        otherButtonTitles:@"Take Photo With Camera", nil];
        actionSheet.actionSheetStyle = UIActionSheetStyleAutomatic;
        [actionSheet showInView:self.view];
    }

}

else if(libraryAvailable) {

    imagePicker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
    [self presentViewController:imagePicker animated:YES completion:nil];
} else {

    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"No Media Types Available" message:@"The photo library does not contain any images and the camera is unavailable.  Add pictures to your library if you wish to post an image." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];

    [alert show];

}
根据

由于媒体源可能不存在或不可用,设备可能并不总是支持所有源类型。例如,如果尝试从用户的库中拾取图像,而库为空,则此方法返回NO

我已经清除了图书馆中的所有照片,以确认这将起作用,但它仍然以“是”的形式返回。我还检查了UIImagePickerControllerSourceTypeSavedPhotosAlbum,返回的结果也是YES


我在模拟器中执行了重置内容和设置,并在设置菜单中验证设备上没有存储照片。此方法是否在模拟器上不能正常工作,或者我做错了什么?

没有照片的照片库与不可用的照片库不同,因此如果没有照片,则看到“是”是完全正确的。如果没有照片,为什么用户不能简单地点击“取消”按钮呢?顺便说一句,你的if/else块不能处理相机可用但照片库不可用的情况。在这种情况下,您应该显示相机。@rmaddy,我刚刚注意到“取消”按钮……所有导航栏项目都设置为白色,因此它混合到我看不到的地方。直到我查看了苹果的示例代码,我才看到“取消”按钮……对于没有照片的库,您是否阅读文档中的语句来说明用户的库是否为空此方法返回否?也许这是一个不正确的声明在文件中…?事实上,这不是很好的捕获谢谢你…