Git Product home page Git Product logo

alassetslibrary-customphotoalbum's Introduction

ALAssetsLibrary-CustomPhotoAlbum

A nice ALAssetsLibrary category for saving images into custom photo album by @MarinTodorov.

Usage

//      |image|: The target image to be saved
//  |albumName|: Custom album name
// |completion|: Block to be executed when succeed to write the image data
//               to the assets library (camera roll)
//    |failure|: Block to be executed when failed to add the asset to the
//               custom photo album
- (void)saveImage:(UIImage *)image
          toAlbum:(NSString *)albumName
       completion:(ALAssetsLibraryWriteImageCompletionBlock)completion
          failure:(ALAssetsLibraryAccessFailureBlock)failure;

And for video:

//   |videoUrl|: The target video to be saved
//  |albumName|: Custom album name
// |completion|: Block to be executed when succeed to write the image data
//               to the assets library (camera roll)
//    |failure|: Block to be executed when failed to add the asset to the
//               custom photo album
- (void)saveVideo:(NSURL *)videoUrl
          toAlbum:(NSString *)albumName
       completion:(ALAssetsLibraryWriteImageCompletionBlock)completion
          failure:(ALAssetsLibraryAccessFailureBlock)failure;

Write the image data with meta data to the assets library (camera roll).

//  |imageData|: The image data to be saved
//  |albumName|: Custom album name
//   |metadata|: Meta data for image
// |completion|: Block to be executed when succeed to write the image data
//    |failure|: block to be executed when failed to add the asset to the custom photo album
- (void)saveImageData:(NSData *)imageData
              toAlbum:(NSString *)albumName
             metadata:(NSDictionary *)metadata
           completion:(ALAssetsLibraryWriteImageCompletionBlock)completion
              failure:(ALAssetsLibraryAccessFailureBlock)failure;

Dependence

  1. AssetsLibrary.framework
  2. MobileCoreServices.framework
  3. Photos.framework (for iOS 8+ projects)

REFERENCE

Contributors

@MarinTodorov
@Kjuly
@coryjthompson
@speedyapocalypse
@blazingpair (@paulz)
@ajcollins
@wka
@NSFish
@michaelcameron

alassetslibrary-customphotoalbum's People

Contributors

ajcollins avatar blazingpair avatar cojoj avatar kjuly avatar michaelcameron avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

alassetslibrary-customphotoalbum's Issues

iOS9 saving bug.

I've been using this library for a while and since I got it working correctly I haven't had any issues.

However, now I'm noticing on iOS 9 (now running WKWebView instead of UIWebView, not sure if that makes a difference), that when I save, it saves to my custom album, camera roll (not a problem as that's supposed to happen), but it saves to a Screenshot folder as well.

Tested in iOS 8 simulator, no screenshot folder.

Is this a iOS 9 issue? Library issue? WKWebView issue?

Thanks for any feedback.

Several leaks in Demo (maybe exists in lib, or only on iOS 7).

  • __NSCFNumber: Foundation: -[NSPlaceholderNumber initWithDouble:]
  • __NSDictionaryl: PhotoLibrary: -[CAMHardwareLockIndicatorView -_commonCAMHardwareLockIndicatorViewInitialization]
  • CAMBlurredSnapshotView: PhotoLibrary: -[PLCameraView _newSnapshotView]
  • CAMHardwareLockIndicatorView: -[PLCameraView _createHardwareLockIndicatorIfNecessary]
  • UIKit: GetContextStack
  • CALayer: UIKit: -[UIView _createLayerWithFrame:]
  • QuartzCore: mem_alloc

etc.

Performance issues with lots of Memory Warnings

Having downloaded the latest version of the library I'm seeing horrible performance even in the provided Demo App. In my own app I'm getting Memory Warnings regularly. while saving the image. What can be causing them? Attached are 2 profile logs, first of your demo app and second - of my own app implementing your library. Tested on the latest iOS 6 version on iPhone 4S.
01
02

Not working on iOS8

Getting this error on iOS8

Error Domain=LIB_ALAssetsLibrary_CustomPhotoAlbum Code=0 "ALAssetsGroup failed to add asset: ALAsset - Type:Photo, URLs:assets-library://asset/asset.PNG?id=34FFE0D1-08BB-45DA-9C91-50D96F6158B9&ext=PNG." UserInfo=0x17927cec0 {NSLocalizedDescription=ALAssetsGroup failed to add asset: ALAsset - Type:Photo, URLs:assets-library://asset/asset.PNG?id=34FFE0D1-08BB-45DA-9C91-50D96F6158B9&ext=PNG.}

Error whilst saving first image to a new album after reinstalling app

As far as I can tell (I've stripped my code right down to test it so hopefully someone else can replicate the issue with different code), whenever you first save an image to the custom album, or move an existing image to the custom album the failure block fires. The image is saved, but only to the camera roll. The custom album is also created but is empty. Once the album has been created all images are saved or moved with no errors.

Thanks!

The demo is very good!
Thank you very much.

HI~Sir, I have a problem

_45-[EXUShareItModelVC createAlbumInPhoneAlbum:]_block_invoke_3: Failed to add the asset to the custom photo album: ALAssetsGroup failed to add asset: ALAsset - Type:Photo, URLs:assets-library://asset/asset.PNG?id=6C63CC8A-2060-42D6-8135-16AB635CB037&ext=PNG.

Failure Block isn't working properly.

Hello Dev,
I'm facing issue in load images method, where it's failure block doesn't work, when tries to search an unavailable or not created album or previously deleted album. Please Help.

Method to remove image from Camera Roll.

Hi,
I could save my Captured image in Custom Photo Album, However along with it the image gets stored in camera roll, any method to remove images saved in camera roll or else can we restrict it from storing to Camera Roll.

addAssetURLToAlbum no longer public

Hi,
Using the code previously hosted on touchcode it was possible to move an existing image to the custom album. With the github code it seems the public methods only allow saving to the custom album such that if the imagepicker selects an existing image from the camera roll (rather than a new one from the camera) it will resave the image into the custom album, creating a new copy.
Any chance of opening up the method to allow moving images to custom albums?
Nick

Saving bulk images fails!

I am using the code mentioned in issue #2. But, when I try to save 17 images or so it works fine for some images and the process fails and gives following error:

_block_invoke238: Failed to add the asset to the custom photo album: Write busy

and only some images get save to the album. The problem is that the for loop is not waiting for the image to save or fail and it's firing multiple save requests... which overloads the writeImageToSavedPhotosAlbum method.

Completion handler

Why both completion and failure blocks take NSError parameters?

[assetsLibrary saveImageData:imageData toAlbum:@"Album" metadata:metadata 
completion:^(NSURL *assetURL, NSError *error) {
    // ...
} failure:^(NSError *error) {
    // ...
}];

ios 8.3 recreate album

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.

save many photos

only the first image saved when trying to save several photos using for loop

ios8.4 sometimes fail when addAssetURL to album

  • (void)assetForURL:(NSURL *)assetURL resultBlock:(ALAssetsLibraryAssetForURLResultBlock)resultBlock failureBlock:(ALAssetsLibraryAccessFailureBlock)failureBlock;

this function sometime return nil, which will lead the saveimage to failureblock.

not working iOS 11.3 , and 11.4 ?

if latest iOS 11.3 and 11.4 then not working this one framework , how to solve out this one problem. if iOS 11.0 below then working . save image and video custom folder then not create and not display photo library . how to solve out this one problem

Retrieve the image

This is a Pull Request in fact:
How to retrieve any image i want ? ( there is no such thing in README )

Image getting saved to Camera roll as well.

Hi,
Thanks for your reply. I want to save my images only to a particular folder. I don't want to save it in the camera roll. (just like Instagram is doing). I am using the following code to save images.

-(void)saveImage:(UIImage*)image toAlbum:(NSString*)albumName withCompletionBlock:(SaveImageCompletion)completionBlock
{
    //write the image data to the assets library (camera roll)
    [self writeImageToSavedPhotosAlbum:image.CGImage orientation:(ALAssetOrientation)image.imageOrientation 
                        completionBlock:^(NSURL* assetURL, NSError* error) {
                               //error handling
                          if (error!=nil) {
                              completionBlock(error);
                              return;
                          }
           //add the asset to the custom photo album
                          [self addAssetURL: assetURL 
                                    toAlbum:albumName 
                        withCompletionBlock:completionBlock];
                           }];
}

Can't create album with same name as a deleted one

First, I call saveImage:toAlbum method and it work well, the "Ablum1' is created.

Second, I delete "Album1", and run the code again. I get this error in this method
_assetForURLResultBlockWithGroup

What's your suggestions? Thanks!

Need to import UIKit with iOS 8

I have successfully used your category in the past and was now attempting to use it with some iOS 8 code (including some Swift).

I ran across the error:
"Expected a type"
which referenced UIImage in the header file in the code:

  • (void)saveImage:(UIImage *)image

I fixed this by adding the following to the header:
@import UIKit;

When custom album was deleted by somebody through system PhotoApp, execute -saveImage:toAlbum:completion:failure:will throw error

Error Domain=LIB_ALAssetsLibrary_CustomPhotoAlbum Code=0 "ALAssetsGroup failed to add asset: ALAsset - Photo, URLs:assets-library://asset/jpg?id=DB9A4152-9517-43D3-A587-5D5A8A50DAE3&ext= jpg." UserInfo=0x17027a740 {NSLocalizedDescription=ALAssetsGroup failed to add asset: ALAsset - Photo, URLs:assets-library://asset/jpg?id=DB9A4152-9517-43D3-A587-5D5A8A50DAE3&ext=jpg.}

ALAssetsGroup failed to add asset: null on iOS11

Hi @Kjuly I am using the latest version of your library but i am facing this issue on IOS 11: ALAssetsGroup failed to add asset: null.I am sure i added the Photos.framework to my Project.I run your ALAssetsLibraryCustomPhotoAlbum_BasicDemo in my iPhone6, and i am also facing this issue.Any help would be great.

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[ALAssetsLibrary saveImage:toAlbum:completion:failure:]: unrecognized selector sent to instance

Hi there, I'm using XCode 6.3 and Swift 1.2 and when runing the code:
ALAssetsLibrary().saveImage(screenshot, toAlbum: "myAlbum", completion:nil, failure:nil)

I get the error:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[ALAssetsLibrary saveImage:toAlbum:completion:failure:]: unrecognized selector sent to instance

I use a bridging header to link the Objective C code with Swift

In the build phases I added the MobileCoreService and the AssetsLibrary framework

Any help would be much appreciated

App Freezing when 100+ photos are send for writting

The application Freezes when 100+ requests are send for writting. Upon faliour i am iterating the same method for writting. Here the code.

- (void)savingDownloadedImages : (UIImage *)img withDictionary:(NSDictionary*)dic {
    NSString *albumName     = dic[kPhotoAlbumName];

    ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
    [library saveImage:img toAlbum:albumName completion:^(NSURL *assetUrl, NSError *error) {
        if (error) {
            [self savingDownloadedImages:img withDictionary:dic];
        }
    } failure:^(NSError *error){
        [self savingDownloadedImages:img withDictionary:dic];
    }];
}

Multithreading violation in iOS 8.3+

It seems that running with -com.apple.CoreData.ConcurrencyDebug 1 generates a crash when using saveVideo:toAlbum:completion: on iOS 8.3 and higher. I am still working through finding the exact issue but I suspect something related to PhotoKit.

The crash is [NSManagedObjectContext __Multithreading_Violation_AllThatIsLeftToUsIsHonor__] it is reproducible with both the device and simulator. Seems like it is trying to deallocate a batch request of some sort.

I will let you know if I determine the root cause. If anyone has seen this issue please let me know. This is debugging with Xcode 6.4

Not saving images in iOS 10

The method - (void)saveImage:(UIImage *)image toAlbum:(NSString *)albumName completion:(ALAssetsLibraryWriteImageCompletionBlock)completion failure (ALAssetsLibraryAccessFailureBlock)failure; doesn't save images to photos

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.