Kjuly / ALAssetsLibrary-CustomPhotoAlbum

A nice ALAssetsLibrary category for saving images & videos into custom photo album.
http://www.touch-code-magazine.com/ios5-saving-photos-in-custom-photo-album-category-for-download/
MIT License
405 stars 101 forks source link

ios 8.3 recreate album #29

Closed bosspopuli closed 9 years ago

bosspopuli commented 9 years ago

Anyone know if the iOS 8.3 has become the problem of storing photos in album a deleted before?

I have this nserror:

Error Domain=LIB_ALAssetsLibrary_CustomPhotoAlbum Code=0 "ALAssetsGroup failed to add asset: ALAsset - Type:Photo, URLs:assets-library://asset/asset.JPG?id=7721AB18-4B9D-46E1-8DC5-2196E6E26F0F&ext=JPG." UserInfo=0x1754663c0 {NSLocalizedDescription=ALAssetsGroup failed to add asset: ALAsset - Type:Photo, URLs:assets-library://asset/asset.JPG?id=7721AB18-4B9D-46E1-8DC5-2196E6E26F0F&ext=JPG.}

EDIT: i modify the code with example and now i have this error:

__29-[TicketViewController photo]_block_invoke417: Failed to add the asset to the custom photo album: ALAssetsGroup failed to add asset: ALAsset - Type:Photo, URLs:assets-library://asset/asset.JPG?id=DBF214F4-4D16-4A05-B6E0-11A636B13317&ext=JPG.

Kjuly commented 9 years ago

What's ur lib version used? Have u add reference of Photos.framework? Plz take a look at this issue (https://github.com/Kjuly/ALAssetsLibrary-CustomPhotoAlbum/issues/16) first, maybe will helps.

bosspopuli commented 9 years ago

Yes i import Photos.framework. and i use the last versión. The code allways pass for this else

 else {
          // code that always creates an album on iOS 7.x.x but fails
          // in certain situations such as if album has been deleted
          // previously on iOS 8.x.
          [self addAssetsGroupAlbumWithName:albumName
                                resultBlock:addPhotoToLibraryBlock
                               failureBlock:failure];
        }
Kjuly commented 9 years ago

Seems u cannot get the PHPhotoLibrary class, can confirm it?

Class PHPhotoLibrary_class = NSClassFromString(@"PHPhotoLibrary");
if (PHPhotoLibrary_class) {
  ...
} else {
   // code that always creates an album on iOS 7.x.x but fails
   // in certain situations such as if album has been deleted
   // previously on iOS 8.x.
   [self addAssetsGroupAlbumWithName:albumName
                         resultBlock:addPhotoToLibraryBlock
                        failureBlock:failure];
}

Wait, u're testing the demo project? Seems the demo project has not imported the framework yet.

bosspopuli commented 9 years ago

The demo project work fine. In my project in a last version worked fine but now don´t work.

captura de pantalla 2015-04-21 a las 11 35 43

This in your class

#import "ALAssetsLibrary+CustomPhotoAlbum.h"
#import <Photos/PHPhotoLibrary.h>

This in my class

-(void)photo{

    UIImage *image = [ImageGenerator imageWithView:self.view];
    NSDateFormatter * dateFormatter = [NSDateFormatter new];
    [dateFormatter setDateFormat:@"YYYYMMDD"];
    _namePhoto = [dateFormatter stringFromDate:[NSDate date]];   
    [ImageGenerator saveImage:image name:_namePhoto];

    [self.library saveImage:image toAlbum:self.sessionData.merchant.merchantName completion:^(NSURL *assetURL, NSError *error) {
        if (error)
            DLog(@"ERROR SAVE ALBUM");
        [self performSelectorOnMainThread:@selector(endPhoto) withObject:nil waitUntilDone:YES];
    } failure:^(NSError *error) {
        DLog(@"FAILURE SAVE ALBUM");        
        [self performSelectorOnMainThread:@selector(endPhoto) withObject:nil waitUntilDone:YES];
    }];
}

Allways return "failure save album" and not recognize PHPhotoLibrary...

This Image is saved in the camera roll

Kjuly commented 9 years ago

Step 1

Generally, the failure block will be invoked if user denied ur app to access to the assets library. Plz make sure ur app is allowed to access the photos app in Settings.app after u upgraded ur system version.


Step 2

Seems u want to change the name for photo, then save it to album. Plz comment out the code snippet below to avoid other factors before do testing first.

NSDateFormatter * dateFormatter = [NSDateFormatter new];
[dateFormatter setDateFormat:@"YYYYMMDD"];
_namePhoto = [dateFormatter stringFromDate:[NSDate date]];   
[ImageGenerator saveImage:image name:_namePhoto];

Step 3

Check the value of image & self.sessionData.merchant.merchantName, make sure they're the one u want.

bosspopuli commented 9 years ago

In the Navigation project appear the Photos.framework but not in the target. I add the framework again and it works!!! Really thanks! When the xcode updated, it removed my framework...

Thanks again!

Kjuly commented 9 years ago

Haha, cool!