Search Results for

    Show / Hide Table of Contents

    Photo Library

    You can capture videos directly to the Photo Library on macOS and iOS.

    Requirements

    macOS

    macOS 10.15 and later is required.

    Note

    Photo Library support is not available in the Unity editor on macOS, because the required usage description keys are not included in the Unity Editor applications Info.plist file.

    iOS

    iOS 11.0 and later is required.

    Usage

    Select Photo Library from the Folder dropdown menu in the Output section of the capture component inspector as shown.


    alt_text

    If you want your captures to be added to an album, put the desired album name in the Subfolder(s) text field. Adding captures to an an album will required full read/write access to the photo library.


    alt_text

    You will need to request permission from the user in order to be able to access the photo library. To do this fill in the relevant usage description in the AVPro Movie Capture section of the Project Settings inspector as shown below. These fields should be added to your generated application or Xcode project as part of the build process.


    alt_text

    You can then request authorisation using the following code snippet where capture is the capture component instance:

    IEnumerator Start()
    {
    #if (UNITY_STANDALONE_OSX || UNITY_IOS) && !UNITY_EDITOR
        CaptureBase.PhotoLibraryAccessLevel photoLibraryAccessLevel = CaptureBase.PhotoLibraryAccessLevel.AddOnly;
    
        // If we're trying to write to the photo library, make sure we have permission
        if (capture.OutputFolder == CaptureBase.OutputPath.PhotoLibrary)
        {
            // Album creation (album name is taken from the output folder path) requires read write access.
            if (capture.OutputFolderPath != null && capture.OutputFolderPath.Length > 0)
                photoLibraryAccessLevel = CaptureBase.PhotoLibraryAccessLevel.ReadWrite;
    
            switch (CaptureBase.HasUserAuthorisationToAccessPhotos(photoLibraryAccessLevel))
            {
                case CaptureBase.PhotoLibraryAuthorisationStatus.Authorised:
                    // All good, nothing to do
                    break;
    
                case CaptureBase.PhotoLibraryAuthorisationStatus.Unavailable:
                    Debug.LogWarning("The photo library is unavailable, will use RelativeToPeristentData instead");
                    capture.OutputFolder = CaptureBase.OutputPath.RelativeToPeristentData;
                    break;
    
                case CaptureBase.PhotoLibraryAuthorisationStatus.Denied:
                    // User has denied access, change output path
                    Debug.LogWarning("User has denied access to the photo library, will use RelativeToPeristentData instead");
                    capture.OutputFolder = CaptureBase.OutputPath.RelativeToPeristentData;
                    break;
    
                case CaptureBase.PhotoLibraryAuthorisationStatus.NotDetermined:
                    // Need to ask permission
                    yield return CaptureBase.RequestUserAuthorisationToAccessPhotos(photoLibraryAccessLevel);
                    // Nested switch, everbodies favourite
                    switch (CaptureBase.HasUserAuthorisationToAccessPhotos(photoLibraryAccessLevel))
                    {
                        case CaptureBase.PhotoLibraryAuthorisationStatus.Authorised:
                            // All good, nothing to do
                            break;
    
                        case CaptureBase.PhotoLibraryAuthorisationStatus.Denied:
                            // User has denied access, change output path
                            Debug.LogWarning("User has denied access to the photo library, will use RelativeToPeristentData instead");
                            capture.OutputFolder = CaptureBase.OutputPath.RelativeToPeristentData;
                            break;
    
                        case CaptureBase.PhotoLibraryAuthorisationStatus.NotDetermined:
                            // We were unable to request access for some reason, check the logs for any error information
                            Debug.LogWarning("Authorisation to access the photo library is still undetermined, will use RelativeToPeristentData instead");
                            capture.OutputFolder = CaptureBase.OutputPath.RelativeToPeristentData;
                            break;
                    }
                    break;
            }
        }
    #endif
        yield return null;
    }
    
    In This Article