Search code examples
iosinsertuiimagepickercontrollernsdatabulk

Importing multiple photos to Saved Photos Album


I'm trying to import multiple photos (that are in the application's sandbox) to the Camera Roll (Saved Photos Album).

I'm performing a selector in background in which I read the data from the filepath and then use UIImageWriteToSavedPhotosAlbum to finish the operation. I'm now testing on large images with Instruments and I can't see any significant memory increase (max Living bytes around 8MB) but the app is still crashing if I try to import ~20 images. It gives me a memory warning but I can't find out what's wrong.

I'm also using an @autoreleasepool around the code which reads the file from the disk (and decrypts it).

In another section of my code, I'm importing images from ALAssetsLibrary with almost the same procedure (encrypting data) and works perfectly fine with over 200 images. No memory warning, no crash.

Any ideas on how to bulk write images to Saved Photos Library?

PS: I basically have this in my import method:

UIImageWriteToSavedPhotosAlbum(decryptedImage, self, @selector(image:didFinishSavingWithError:contextInfo:), nil);

and then in the didFinishSaving callback, I call the import method again which goes though an array of filepaths to be imported.

It works perfectly fine on smaller files, but larger files produce a crash.

Thanks!

Edit: Just tried to load a large image with [UIImage imageNamed:] and the app still crashes. So I guess it's the UIImageWriteToSavedPhotosAlbum methods problem? How should I import larger images?


Solution

  • I ended up using ALAssetsLibrary's method writeImageDataToSavedPhotosAlbum:metadata:completionBlock: and it works flawlessly! No memory warnings and/or crashes.