Save image to a specific photo album with photo framework ios 8

怎甘沉沦 提交于 2019-12-11 19:38:53

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!