QQ group inside see someone asked to save the picture to a custom album method:
Directly on the code:
#import <Foundation/Foundation.h>#import <AssetsLibrary/AssetsLibrary.h> void (^saveimagecompletion) (nserror* error); @interface alassetslibrary (Customphotoalbum)-(void) SaveImage: (uiimage*) Image toalbum: (nsstring*) Albumname Withcompletionblock: (saveimagecompletion) Completionblock; -(void) Addasseturl: (nsurl*) Asseturl toalbum: (nsstring*) albumname Withcompletionblock: ( saveimagecompletion) Completionblock; @end
#import "alassetslibrary+customphotoalbum.h"@implementationalassetslibrary (customphotoalbum)-(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]; }];}-(void) Addasseturl: (nsurl*) Asseturl toalbum: (nsstring*) albumname Withcompletionblock: (saveimagecompletion) completionblock{__block BOOL albumwasfound=NO; //Search all photo albums in the Library[Self enumerategroupswithtypes:alassetsgroupalbum usingblock:^ (Alassetsgroup *group, BOOL *stop) { //Compare the names of the albums if([Albumname Compare: [Group valueforproperty:alassetsgrouppropertyname]]==nsorderedsame) { //Target album is foundAlbumwasfound =YES; //get a hold of the photo ' s asset instance[Self assetforurl:asseturl resultblock:^ (Alasset *Asset) { //add photo to the target album[group Addasset:asset]; //Run the completion blockCompletionblock (nil); } Failureblock:completionblock]; //album is found, bail out of the method return; } if(Group==nil && albumwasfound==NO) { //photo albums is over, target album does not exist, thus create it__weak alassetslibrary* Weakself =Self ; //Create new Assets album[Self addassetsgroupalbumwithname:albumname Resultblock:^ (Alassetsgroup *Group) { //get the photo ' s instance[Weakself Assetforurl:asseturl Resultblock:^ (Alasset *Asset) { //add photo to the newly created album[group Addasset:asset]; //Call the completion blockCompletionblock (nil); } Failureblock:completionblock]; } Failureblock:completionblock]; //should is the last iteration anyway, but just in case return; }} Failureblock:completionblock]; }@end
When used, just call:
-(void) SaveImage: (uiimage*) Image toalbum: (nsstring*) albumname withcompletionblock: (saveimagecompletion) Completionblock, you can ...
iOS save pictures to albums you create