我目前正在使用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
只能从自定义相册中选择图片,或者只选择我的应用保存的图片。我该怎么办?