From dc7ef14daceb5165d35a67a63ff1445f7237ac27 Mon Sep 17 00:00:00 2001 From: mark Date: Wed, 31 Mar 2021 17:47:25 +0800 Subject: [PATCH] Fix photo permission request not response once user cancel it --- .../ImagePickerController+Closure.swift | 39 ++++++++++++------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/Sources/Controller/ImagePickerController+Closure.swift b/Sources/Controller/ImagePickerController+Closure.swift index f5d21186..857931aa 100644 --- a/Sources/Controller/ImagePickerController+Closure.swift +++ b/Sources/Controller/ImagePickerController+Closure.swift @@ -55,22 +55,35 @@ import Photos private func authorize(_ authorized: @escaping () -> Void) { if #available(iOS 14, *) { - PHPhotoLibrary.requestAuthorization(for: .readWrite) { (status) in - switch status { - case .authorized, - .limited: - DispatchQueue.main.async(execute: authorized) - default: - break + let immediateStatus = PHPhotoLibrary.authorizationStatus(for: .readWrite) + switch immediateStatus { + case .authorized, + .limited: + DispatchQueue.main.async(execute: authorized) + default: + PHPhotoLibrary.requestAuthorization(for: .readWrite) { (status) in + switch status { + case .authorized, + .limited: + DispatchQueue.main.async(execute: authorized) + default: + break + } } } } else { - PHPhotoLibrary.requestAuthorization { (status) in - switch status { - case .authorized: - DispatchQueue.main.async(execute: authorized) - default: - break + let immediateStatus = PHPhotoLibrary.authorizationStatus() + switch immediateStatus { + case .authorized: + DispatchQueue.main.async(execute: authorized) + default: + PHPhotoLibrary.requestAuthorization { (status) in + switch status { + case .authorized: + DispatchQueue.main.async(execute: authorized) + default: + break + } } } }