iosswiftphotosframeworkphotokit

Disabling the auto request for Photo Library access


I am referring to this request:

The first time your app uses PHAsset, PHCollection, PHAssetCollection, or PHCollectionList methods to fetch content from the library, or uses one of the methods listed in Applying Changes to the Photo Library to request changes to library content, Photos automatically and asynchronously prompts the user to request authorization.

Is there any way to disable this and do it manually instead?


Solution

  • You can't "disable" the automatic request per se, if the authorisation status is undetermined the API will do the request automatically.

    You can, however, request authorisation manually using PHPhotoLibrary.requestAuthorization

    Which might look something like...

    let status = PHPhotoLibrary.authorizationStatus()
    switch status {
    case .notDetermined:
        PHPhotoLibrary.requestAuthorization({ (status) in
            // Check the status and deal with it
        })
    case .restricted: fallthrough
    case .denied: 
        // Deal with it
        break
    case .authorized: 
        // All is good
        break
    }