用相框保存图片到指定相册ios 8
Save image to a specific photo album with photo framework ios 8
我刚刚使用此代码创建了一个新相册:
[[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 和照片框架。
谢谢
您应该将资产添加到 albumRequest
//Create Album
PHAssetCollectionChangeRequest *albumRequest = [PHAssetCollectionChangeRequest creationRequestForAssetCollectionWithTitle:@"ChameleonSensors"];
PHAssetChangeRequest *createImageRequest = [PHAssetChangeRequest creationRequestForAssetFromImage:[UIImage imageNamed:@"test"]];
[albumRequest addAssets:@[createImageRequest.placeholderForCreatedAsset]];
我刚刚使用此代码创建了一个新相册:
[[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 和照片框架。
谢谢
您应该将资产添加到 albumRequest
//Create Album
PHAssetCollectionChangeRequest *albumRequest = [PHAssetCollectionChangeRequest creationRequestForAssetCollectionWithTitle:@"ChameleonSensors"];
PHAssetChangeRequest *createImageRequest = [PHAssetChangeRequest creationRequestForAssetFromImage:[UIImage imageNamed:@"test"]];
[albumRequest addAssets:@[createImageRequest.placeholderForCreatedAsset]];