0

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

MSU_Bulldog
  • 3,501
  • 5
  • 37
  • 73
gemaAD
  • 33
  • 7

1 Answers1

0

you should add assets to albumRequest

    //Create Album
    PHAssetCollectionChangeRequest *albumRequest = [PHAssetCollectionChangeRequest creationRequestForAssetCollectionWithTitle:@"ChameleonSensors"];
    PHAssetChangeRequest *createImageRequest = [PHAssetChangeRequest creationRequestForAssetFromImage:[UIImage imageNamed:@"test"]];
    [albumRequest addAssets:@[createImageRequest.placeholderForCreatedAsset]];
Mikhail
  • 90
  • 7
  • Is it possible to know the path where that image was saved?, – gemaAD Dec 01 '15 at 18:37
  • Yes, a placeholderForCreatedAsset always has the same local identifier as the asset, collection, or collection list that it represents. To find the object that corresponds to a placeholder, read the placeholder’s localIdentifier property and use it to fetch the actual object. – Mikhail Dec 01 '15 at 19:09
  • I have obtained this identifier: 9C41BF95-A9C5-498B-AFFA-6D9CF6B56C21/L0/001. Is it that correct?, now How can i obtain the path? – gemaAD Dec 01 '15 at 19:58
  • the only way i found is [here](http://stackoverflow.com/a/28879226/2463852) . use `requestContentEditingInputWithOptions:` and get `fullSizeImageURL` from `PHContentEditingInput` – Mikhail Dec 01 '15 at 20:45