Commit 37086526 by Daniel Dahan

development: converted PhotoLibrary requestAccess call to dispatch delegation…

development: converted PhotoLibrary requestAccess call to dispatch delegation methods and callback on the main thread async
parent 47da25c8
...@@ -62,7 +62,7 @@ public protocol PhotoLibraryDelegate { ...@@ -62,7 +62,7 @@ public protocol PhotoLibraryDelegate {
/** /**
A delegation method that is executed when the PhotoLibrary status is updated. A delegation method that is executed when the PhotoLibrary status is updated.
- Parameter photoLibrary: A reference to the PhotoLibrary. - Parameter photoLibrary: A reference to the PhotoLibrary.
- Parameter status: A reference to the AuthorizationStatus. - Parameter status: A reference to the PHAuthorizationStatus.
*/ */
@objc @objc
optional func photoLibrary(photoLibrary: PhotoLibrary, status: PHAuthorizationStatus) optional func photoLibrary(photoLibrary: PhotoLibrary, status: PHAuthorizationStatus)
...@@ -214,32 +214,34 @@ extension PhotoLibrary { ...@@ -214,32 +214,34 @@ extension PhotoLibrary {
- Parameter _ completion: A completion block that passes in a PHAuthorizationStatus - Parameter _ completion: A completion block that passes in a PHAuthorizationStatus
enum that describes the response for the authorization request. enum that describes the response for the authorization request.
*/ */
public func requestAuthorization(_ completion: ((PHAuthorizationStatus) -> Void)? = nil) { public func requestAuthorization(_ completion: (@escaping (PHAuthorizationStatus) -> Void)? = nil) {
PHPhotoLibrary.requestAuthorization { [weak self, completion = completion] (status) in PHPhotoLibrary.requestAuthorization { [weak self, completion = completion] (status) in
guard let s = self else { DispatchQueue.main.async { [weak self, completion = completion] in
return guard let s = self else {
} return
}
switch status {
case .authorized:
s.delegate?.photoLibrary?(photoLibrary: s, status: .authorized)
s.delegate?.photoLibrary?(authorized: s)
completion?(.authorized)
case .denied:
s.delegate?.photoLibrary?(photoLibrary: s, status: .denied)
s.delegate?.photoLibrary?(denied: s)
completion?(.denied)
case .notDetermined:
s.delegate?.photoLibrary?(photoLibrary: s, status: .notDetermined)
s.delegate?.photoLibrary?(notDetermined: s)
completion?(.notDetermined)
case .restricted: switch status {
s.delegate?.photoLibrary?(photoLibrary: s, status: .restricted) case .authorized:
s.delegate?.photoLibrary?(restricted: s) s.delegate?.photoLibrary?(photoLibrary: s, status: .authorized)
completion?(.restricted) s.delegate?.photoLibrary?(authorized: s)
completion?(.authorized)
case .denied:
s.delegate?.photoLibrary?(photoLibrary: s, status: .denied)
s.delegate?.photoLibrary?(denied: s)
completion?(.denied)
case .notDetermined:
s.delegate?.photoLibrary?(photoLibrary: s, status: .notDetermined)
s.delegate?.photoLibrary?(notDetermined: s)
completion?(.notDetermined)
case .restricted:
s.delegate?.photoLibrary?(photoLibrary: s, status: .restricted)
s.delegate?.photoLibrary?(restricted: s)
completion?(.restricted)
}
} }
} }
} }
......
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
import Photos import UIKit
open class PhotoLibraryController: UIViewController, PhotoLibraryDelegate { open class PhotoLibraryController: UIViewController, PhotoLibraryDelegate {
/// A reference to a PhotoLibrary. /// A reference to a PhotoLibrary.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment