问题
I have just created a new photo album with this code:
[[PHPhotoLibrary sharedPhotoLibrary] performChanges:^
{
//Checks for App Photo Album and creates it if it doesn't exist
PHFetchOptions *fetchOptions = [PHFetchOptions new];
fetchOptions.predicate = [NSPredicate predicateWithFormat:@"title == %@", @"ChameleonSensors"];
PHFetchResult *fetchResult = [PHAssetCollection fetchAssetCollectionsWithType:PHAssetCollectionTypeAlbum subtype:PHAssetCollectionSubtypeAlbumRegular options:fetchOptions];
if (fetchResult.count == 0)
{
//Create Album
PHAssetCollectionChangeRequest *albumRequest = [PHAssetCollectionChangeRequest creationRequestForAssetCollectionWithTitle:@"ChameleonSensors"];
}
}
completionHandler:^(BOOL success, NSError *error)
{
NSLog(@"Log here...");
if (!success) {
NSLog(@"Error creating album: %@", error);
}else{
NSLog(@"Perfecto");
}
}];
This is ok, but now I need to save photos in this photo album.
I´m using objective-c and photo framework.
thank you
回答1:
you should add assets to albumRequest
//Create Album
PHAssetCollectionChangeRequest *albumRequest = [PHAssetCollectionChangeRequest creationRequestForAssetCollectionWithTitle:@"ChameleonSensors"];
PHAssetChangeRequest *createImageRequest = [PHAssetChangeRequest creationRequestForAssetFromImage:[UIImage imageNamed:@"test"]];
[albumRequest addAssets:@[createImageRequest.placeholderForCreatedAsset]];
来源:https://stackoverflow.com/questions/34022388/save-image-to-a-specific-photo-album-with-photo-framework-ios-8