From 25833a5f40f8c4aa83db93600ff987974f3abdc5 Mon Sep 17 00:00:00 2001 From: mark Date: Wed, 31 Mar 2021 12:55:39 +0800 Subject: [PATCH] Fix request photo auth method for iOS 14 --- .../ImagePickerController+Closure.swift | 23 ++++++++++++++----- 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/Sources/Controller/ImagePickerController+Closure.swift b/Sources/Controller/ImagePickerController+Closure.swift index 2b98e6e1..05a9a639 100644 --- a/Sources/Controller/ImagePickerController+Closure.swift +++ b/Sources/Controller/ImagePickerController+Closure.swift @@ -54,12 +54,23 @@ import Photos } private func authorize(_ authorized: @escaping () -> Void) { - PHPhotoLibrary.requestAuthorization { (status) in - switch status { - case .authorized: - DispatchQueue.main.async(execute: authorized) - default: - break + if #available(iOS 14, *) { + PHPhotoLibrary.requestAuthorization(for: .readWrite) { (status) in + switch status { + case .authorized: + DispatchQueue.main.async(execute: authorized) + default: + break + } + } + } else { + PHPhotoLibrary.requestAuthorization { (status) in + switch status { + case .authorized: + DispatchQueue.main.async(execute: authorized) + default: + break + } } } }