Skip to content

Save Image to Camera Roll

Stanislav Osipov edited this page Mar 28, 2020 · 2 revisions

Saving any texture to the camera roll is fairly simple and can be accomplished with ISN_PhotoAlbum class. The example below adds the specified image to the user’s Camera Rol. When used on an iOS device without a camera, this method adds the image to the Saved Photos album rather than to the Camera Roll album.

using SA.iOS.UIKit;
...
Texture2D myImage = GetImage();
ISN_PhotoAlbum.UIImageWriteToSavedPhotosAlbum(myImage, (result) => {
    if(result.IsSucceeded) 
        Debug.Log("Image saved");
    else 
        Debug.Log("Error: " + result.Error.Message);
});

Based on iOS UIKit::UIImageWriteToSavedPhotosAlbum
There is also an ability to save a screenshot out of the box:

using SA.iOS.UIKit;
...
ISN_PhotoAlbum.SaveScreenshotToCameraRoll((result) => {
    if (result.IsSucceeded) 
        Debug.Log("screenshot saved saved");
    else 
        Debug.Log("Error: " + result.Error.Message);
    
});

Important: Do not forget that you can use Photo Library related API, only after a user has authorized access to Photo Library for your app. If you try to use API without authorization, the system will ask for permission automatically. If a user allows Photo Library access, you good, otherwise, an operation will be failed, and you may not even receive a callback from the method. So it's in your best interest to request user authorization before you attempt to use a Photo Library.

About

Foundation

AV Foundation

App Tracking Transparency

Game Kit

Store Kit

UI Kit

Social

Replay Kit

Contacts

AVKit

Photos

App Delegate

User Notifications

MediaPlayer

Core Location

AdSupport

EventKit

CloudKit

Authentication Services

XCode

Knowledge Base

Clone this wiki locally