我可以从相机胶卷中选择图像,然后将其保存到自定义相册中。 由于重复保存,这会增加计数
我该怎么做才能删除资产或其他任何方式?
__block UIImage *imTransfer=nil;
PHImageRequestOptions * imageRequestOp = [[PHImageRequestOptions alloc] init];
imageRequestOp.synchronous = YES;
[[PHImageManager defaultManager] requestImageDataForAsset:photoAssety options:imageRequestOp resultHandler:^(NSData *imageData, NSString *dataUTI, UIImageOrientation orientation, NSDictionary *info) {
imTransfer=[UIImage imageWithData:imageData];
NSLog(@"info = %@", imTransfer);
}];
__block PHFetchResult *photosAsset;
__block PHAssetCollection *collection;
__block PHObjectPlaceholder *placeholder;
// Find the album
PHFetchOptions *fetchOptions = [[PHFetchOptions alloc] init];
fetchOptions.predicate = [NSPredicate predicateWithFormat:@"title = %@", BottomAlbumName_string];
collection = [PHAssetCollection fetchAssetCollectionsWithType:PHAssetCollectionTypeAlbum
subtype:PHAssetCollectionSubtypeAny
options:fetchOptions].firstObject;
// Create the album
if (!collection)
{
[[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{
PHAssetCollectionChangeRequest *createAlbum = [PHAssetCollectionChangeRequest creationRequestForAssetCollectionWithTitle:BottomAlbumName_string];
placeholder = [createAlbum placeholderForCreatedAssetCollection];
} completionHandler:^(BOOL success, NSError *error) {
if (success)
{
PHFetchResult *collectionFetchResult = [PHAssetCollection fetchAssetCollectionsWithLocalIdentifiers:@[placeholder.localIdentifier]
options:nil];
collection = collectionFetchResult.firstObject;
}
}];
}
// Save to the album
[[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{
PHAssetChangeRequest *assetRequest = [PHAssetChangeRequest changeRequestForAsset:photoAssety];
placeholder = [assetRequest placeholderForCreatedAsset];
photosAsset = [PHAsset fetchAssetsInAssetCollection:collection options:nil];
PHAssetCollectionChangeRequest *albumChangeRequest = [PHAssetCollectionChangeRequest changeRequestForAssetCollection:collection
assets:photosAsset];
// [albumChangeRequest removeAssets:@[placeholder].firstObject];
[albumChangeRequest addAssets:@[placeholder]];
[self toggleFavoriteForAsset:photoAssety];
} completionHandler:^(BOOL success, NSError *error) {
if (success)
{
// NSString *UUID = [placeholder.localIdentifier substringToIndex:36];
// self.photo.assetURL = [NSString stringWithFormat:@"assets-library://asset/asset.PNG?id=%@&ext=JPG", UUID];
// [self savePhoto];
}
else
{
NSLog(@"%@", error);
}
}];