I don't know friends have wood have to do too much diagram saved to the System album this need, I am using 'uiimagewritetosavedphotosalbum' to save the picture, in the proxy callback party ' There are some images in didfinishsavingwitherror ' that will have this error:
The reason above is very clear, at the same time to save multiple graphs, system resources are limited, too late to process all the pictures, prone to write errors. This error will not occur if you save another one after saving.
In fact, the management of the album is ' Alassetslibrary ' This class, Apple's official description of it is this:an instance of Alassetslibrary provides access to the videos and Photos that is under the control of the photos application. The API saved to the album is available in ' alassetslibrary ':
1 //with a UIImage, the API user can use-[uiimage Cgimage] to get a cgimageref, and cast-[uiimage imageorientation] to Alassetorientation.2- (void) Writeimagetosavedphotosalbum: (cgimageref) imageref orientation: (alassetorientation) Orientation Completionblock: ( Alassetslibrarywriteimagecompletionblock) Completionblock Ns_deprecated_ios (4_0, 9_0,"Use Creationrequestforassetfromimage:on phassetchangerequest from the Photos framework to create a new asset instead< /c2>");3 4 //The API user'll has to specify the orientation key on the metadata dictionary to preserve the orientation of the I Mage5- (void) Writeimagetosavedphotosalbum: (cgimageref) Imageref metadata: (nsdictionary *) metadata completionblock: ( Alassetslibrarywriteimagecompletionblock) Completionblock Ns_deprecated_ios (4_1, 9_0,"Use Creationrequestforassetfromimage:on phassetchangerequest from the Photos framework to create a new asset instead< /c2>");6 7 //If There is a conflict between the metadata in the image data and the metadata dictionary, the image data metadata VA Lues 'll be overwritten8- (void) Writeimagedatatosavedphotosalbum: (NSData *) ImageData metadata: (nsdictionary *) metadata completionblock: ( Alassetslibrarywriteimagecompletionblock) Completionblock Ns_deprecated_ios (4_1, 9_0,"Use Creationrequestforassetfromimagedata:on phassetchangerequest from the Photos framework to create a new asset Inst EAD");
The next two metadata that need to provide the picture, I use the first method. The following code ~
1. Initialize a global ' alassetslibrary '
1 alassetslibrary *assetslibrary = [[Alassetslibrary alloc] init];
2. Encapsulate a method, place the picture that needs to be saved in an array, take the first one at a time, call ' Writeimagetosavedphotosalbum ' Save, if the save succeeds, then move it to the group, save the next one, if there is an error, I am using a bool variable ' isimagessavedfailed ' to record (I need the picture to save all the success).
1typedefvoid(^completion_t) (IDresult);2 3 4- (void) Writeimages: (nsmutablearray*) Images5 completion: (completion_t) Completionhandler {6 if([images count] = =0) {7 if(completionhandler) {8 //Signal completion to the Call-site. Use of an appropriate result,9 //instead of @ "finished" possibly pass an array of URLs and NserrorsTen //generated below in "Handle URL or error". OneCompletionhandler (@"images is all saved."); A } - return; - } theuiimage* image =[Images Firstobject]; - [Assetslibrary writeimagetosavedphotosalbum:image. Cgimage - Orientation:alassetorientationup -completionblock:^ (Nsurl *asseturl, Nserror *error) { + //Caution:check The execution context-it is any thread, - //possibly use Dispatch_async to dispatch to the main thread or + //Any other queue. A //handle URL or error at if(Error) { -NSLog (@"error =%@", [Error localizeddescription]); -isimagessavedfailed =true; - return; - } -[Images Removeobjectatindex:0]; in //Next Image: - [self writeimages:images completion:completionhandler]; to }]; +}
3. Invoking the sample
1Nsmuatablearray *saveimages;//Pictures saved to an album2[Self writeimages:saveimages completion:^ (IDresult) {3NSLog (@"Result:%@", result);4 [HUD stoploading];5 if(isimagessavedfailed) {6 //handle failed.7}Else{8 //handle success.9 }Ten}];
Reference Link: http://stackoverflow.com/questions/20662908/ios-programming-using-threads-to-add-multiple-images-to-library
======================= Split Line ===============================
Long time Wood has written a blog, there are a lot of things Wood records, or recorded under the impression of a bit.
IOS multiple pictures saved to album issue (add multiple images to photo album)