如何防止隐藏的相册出现在CTAssetsPickerController上

时间:2016-04-06 01:29:07

标签: ios objective-c uiimagepickercontroller

我正在使用CTAssetsPickerController http://blog.rooday.com/从照片应用中导入图片。我想禁用从隐藏的'一些用户可能拥有的专辑。如果你有什么应用程序和隐藏的相册,你会注意到你无法从所述相册导入。我希望能够做同样的事情,但一直在寻找几个小时,而且还没有到达任何地方。感谢您的帮助

 - (void)showImagePickerForSourceType:(UIImagePickerControllerSourceType)sourceType {
// Create the image picker
// request authorization status
[PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus status){
    dispatch_async(dispatch_get_main_queue(), ^{

        // init picker
        self.imagePickerController = [[CTAssetsPickerController alloc] init];

        // set delegate
        self.imagePickerController.delegate = self;
        // create options for fetching photo only
        PHFetchOptions *fetchOptions = [PHFetchOptions new];
        fetchOptions.predicate = [NSPredicate predicateWithFormat:@"mediaType == %d", PHAssetMediaTypeImage];

        // assign options
        self.imagePickerController.assetsFetchOptions = fetchOptions;

        // Optionally present picker as a form sheet on iPad
        if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
            self.imagePickerController.modalPresentationStyle = UIModalPresentationFormSheet;

        // present picker
        [self presentViewController:self.imagePickerController animated:YES completion:nil];
    });
}];

2 个答案:

答案 0 :(得分:1)

查看CTAssetsPickerController的repo,似乎可以通过将名为assetCollectionSubtype的属性设置为整数值数组来设置相册类型,该数组对应于Apple的PHAssetCollectionSubtype枚举。 https://developer.apple.com/library/ios/documentation/Photos/Reference/PHAssetCollection_Class/#//apple_ref/c/tdef/PHAssetCollectionSubtype

答案 1 :(得分:0)

经过一番研究后,我发现框架有一个委托方法,可以让你禁用资产。

为了解决我的问题,我实现了这个方法:

- (BOOL)assetsPickerController:(CTAssetsPickerController *)picker shouldEnableAsset:(PHAsset *)asset {
     return !asset.isHidden;
}

隐藏的相册仍会显示,但从中导入会被禁用。