Search code examples
iosdebuggingfilesystemsshared-file

How can I write image files in iOS such that I can open them in the built in Photos app?


I'm pretty new to iOS development and I need the ability to dump some open GL framebuffers to png files for rendering engine debug purposes. I've found some great boilerplate code out there for doing this by reading the buffer into a UIImage object and write it as a png file.

In most cases of others asking about something like this, they've wanted to dump an image view and programmatically pick it up later, so the directory they're writing the files to is one of the app's private directories.

I'd like to do this simply for debugging purposes, so I'd like to be able to see the frame buffer images in the built in Photos app. Is there a way to write these photos so that they show up in the Photos app? I'm assuming there must be apps out there that write photos into this storage (e.g. picture editing software). Below is what I've seen recommended other places on SO, but I believe these write to the public Pictures directory. Perhaps I'm missing a permission, like I said, still new.

        NSArray *paths = NSSearchPathForDirectoriesInDomains(NSPicturesDirectory, NSUserDomainMask, YES);
        NSString *picsDirectory = [paths objectAtIndex:0];
        NSString *dataPath = [picsDirectory stringByAppendingPathComponent:name];

Solution

  • Use UIImageWriteToSavedPhotosAlbum ( UIImage *image, id completionTarget, SEL completionSelector, void *contextInfo )

    https://developer.apple.com/library/ios/documentation/uikit/reference/UIKitFunctionReference/index.html#//apple_ref/doc/uid/TP40006894-CH3-SW29