繁体   English   中英

使用Photo Framework 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]];

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM