我刚用这段代码创建了一个新的相册:
[[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");
}
}];
这没关系,但现在我需要在这个相册中保存照片。
我正在使用objective-c和照片框架。
谢谢
答案 0 :(得分:0)
您应该将资源添加到albumRequest
//Create Album
PHAssetCollectionChangeRequest *albumRequest = [PHAssetCollectionChangeRequest creationRequestForAssetCollectionWithTitle:@"ChameleonSensors"];
PHAssetChangeRequest *createImageRequest = [PHAssetChangeRequest creationRequestForAssetFromImage:[UIImage imageNamed:@"test"]];
[albumRequest addAssets:@[createImageRequest.placeholderForCreatedAsset]];