本文介绍了使用照片框架ios 8将图像保存到特定的相册的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我刚用这段代码创建了一个新的相册:
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.
我正在使用objective-c和照片框架。
I´m using objective-c and photo framework.
谢谢
推荐答案
您应该将资产添加到albumRequest
you should add assets to albumRequest
//Create Album
PHAssetCollectionChangeRequest *albumRequest = [PHAssetCollectionChangeRequest creationRequestForAssetCollectionWithTitle:@"ChameleonSensors"];
PHAssetChangeRequest *createImageRequest = [PHAssetChangeRequest creationRequestForAssetFromImage:[UIImage imageNamed:@"test"]];
[albumRequest addAssets:@[createImageRequest.placeholderForCreatedAsset]];
这篇关于使用照片框架ios 8将图像保存到特定的相册的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!