禁用照片库访问的自动请求

Disabling the auto request for Photo Library access

我指的是这个请求:

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.

有什么方法可以禁用它并改为手动执行吗?

您不能"disable"自动请求本身,如果授权状态是undetermined,API将执行请求自动。

但是,您可以使用 PHPhotoLibrary.requestAuthorization

手动请求授权

这可能看起来像...

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
}