iOS - UIImagePickerController仅显示特定相册中的图像

时间:2015-05-18 06:45:04

标签: ios objective-c xcode alassetslibrary

我目前正在使用ALAssetsLibrary使用writeImageToSavedPhotosAlbum将我的图片保存到自定义相册中。

[self.assetsLibrary addAssetsGroupAlbumWithName:album
                                      resultBlock:^(ALAssetsGroup *group) {
                                          NSLog(@"added album:%@", album);
                                      }
                                     failureBlock:^(NSError *error) {
                                         NSLog(@"error adding album");
                                     }];


__block ALAssetsGroup* groupToAddTo;
        [self.assetsLibrary enumerateGroupsWithTypes:ALAssetsGroupAlbum
                                    usingBlock:^(ALAssetsGroup *group, BOOL *stop) {
                                        if ([[group valueForProperty:ALAssetsGroupPropertyName] isEqualToString:album]) {
                                            NSLog(@"found album %@", album);
                                            groupToAddTo = group;
                                        }
                                    }
                                  failureBlock:^(NSError* error) {
                                      NSLog(@"failed to enumerate albums:\nError: %@", [error localizedDescription]);
                                  }];


CGImageRef img = [imageToSave CGImage];
        [self.assetsLibrary writeImageToSavedPhotosAlbum:img
                                          metadata:metadata
                                   completionBlock:^(NSURL* assetURL, NSError* error) {
                                       if (error.code == 0) {
                                           NSLog(@"saved image completed:\nurl: %@", assetURL);

                                           // try to get the asset
                                           [self.assetsLibrary assetForURL:assetURL
                                                         resultBlock:^(ALAsset *asset) {
                                                             // assign the photo to the album
                                                             [groupToAddTo addAsset:asset];
                                                             NSLog(@"Added %@ to %@", [[asset defaultRepresentation] filename], album);
                                                         }
                                                        failureBlock:^(NSError* error) {
                                                            NSLog(@"failed to retrieve image asset:\nError: %@ ", [error localizedDescription]);
                                                        }];
                                       }
                                       else {
                                           NSLog(@"saved image failed.\nerror code %li\n%@", (long)error.code, [error localizedDescription]);
                                       }
                                   }];

我希望我的UIImagePickerController只能从自定义相册中选择图片,或者只选择我的应用保存的图片。我该怎么办?

0 个答案:

没有答案