swift 获取相册权限的正确姿势

获取相册时,如果用户(iOS 14以上系统)选择了部分图片允许访问,那么这就需要更新相册的访问权限等级了,不然是拿不到limited的status的:参考
https://www.wwdcnotes.com/notes/wwdc20/10641/

if #available(iOS 14, *) {
            let requiredAccessLevel: PHAccessLevel = .readWrite
            PHPhotoLibrary.requestAuthorization(for: requiredAccessLevel) { (authorizationStatus) in
                switch authorizationStatus{
                case .limited:
                    Logger.log("相册部分")
                case .authorized:
                    Logger.log("相册允许")
                default:
                    Logger.log("相册Unimplemented")
                }
            }
        } else {
            let photoStatus = PHPhotoLibrary.authorizationStatus()
                Logger.log("系统14以下用户相册权限\(photoStatus.rawValue)")
            // Fallback on earlier versions
        }

你可能感兴趣的:(swift 获取相册权限的正确姿势)