From f8e26250c3ec04b758ca943fb26293e6d21ea9d4 Mon Sep 17 00:00:00 2001 From: gautier-gdx Date: Thu, 17 Nov 2016 19:07:36 +0100 Subject: [PATCH 1/7] working on custom View --- Permission.xcodeproj/project.pbxproj | 8 ++++++++ Source/PermissionAlert.swift | 4 +++- Source/Permissionable.swift | 15 +++++++++++++++ Source/UIAlertController+Extension.swift | 20 ++++++++++++++++++++ 4 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 Source/Permissionable.swift create mode 100644 Source/UIAlertController+Extension.swift diff --git a/Permission.xcodeproj/project.pbxproj b/Permission.xcodeproj/project.pbxproj index df14805..14e7139 100644 --- a/Permission.xcodeproj/project.pbxproj +++ b/Permission.xcodeproj/project.pbxproj @@ -32,6 +32,8 @@ 6DF9C2BE1C8F4FE5000710C1 /* Photos.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6DF9C2BD1C8F4FE5000710C1 /* Photos.swift */; }; 6DF9C2C01C8F5003000710C1 /* Events.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6DF9C2BF1C8F5003000710C1 /* Events.swift */; }; 6DF9C2C61C8F5B4C000710C1 /* Location.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6DF9C2C51C8F5B4C000710C1 /* Location.swift */; }; + C2ED3A741DDE2401001071FF /* Permissionable.swift in Sources */ = {isa = PBXBuildFile; fileRef = C2ED3A731DDE2401001071FF /* Permissionable.swift */; }; + C2ED3A761DDE2493001071FF /* UIAlertController+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = C2ED3A751DDE2493001071FF /* UIAlertController+Extension.swift */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -73,6 +75,8 @@ 6DF9C2BD1C8F4FE5000710C1 /* Photos.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Photos.swift; sourceTree = ""; }; 6DF9C2BF1C8F5003000710C1 /* Events.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Events.swift; sourceTree = ""; }; 6DF9C2C51C8F5B4C000710C1 /* Location.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Location.swift; sourceTree = ""; }; + C2ED3A731DDE2401001071FF /* Permissionable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Permissionable.swift; sourceTree = ""; }; + C2ED3A751DDE2493001071FF /* UIAlertController+Extension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIAlertController+Extension.swift"; sourceTree = ""; }; D08FF2891DC3AD2900F28088 /* PermissionFlags.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = PermissionFlags.xcconfig; sourceTree = ""; }; /* End PBXFileReference section */ @@ -124,6 +128,8 @@ 6D0069B31C1868E8002FDB42 /* PermissionSet.swift */, 6D491E771C9CA90B00611006 /* PermissionStatus.swift */, 6D491E751C9CA7DE00611006 /* PermissionType.swift */, + C2ED3A731DDE2401001071FF /* Permissionable.swift */, + C2ED3A751DDE2493001071FF /* UIAlertController+Extension.swift */, ); path = Source; sourceTree = ""; @@ -302,9 +308,11 @@ 6DF9C2C61C8F5B4C000710C1 /* Location.swift in Sources */, 6DA8B4B21BFB8AD8007A94FC /* PermissionAlert.swift in Sources */, 6C04FAF61CCA8F3A00B3F361 /* AddressBook.swift in Sources */, + C2ED3A741DDE2401001071FF /* Permissionable.swift in Sources */, 3D42A7DB1D5F66B300236ABA /* SpeechRecognizer.swift in Sources */, 6DF9C2BE1C8F4FE5000710C1 /* Photos.swift in Sources */, 6DF9C2BA1C8F4FAC000710C1 /* Microphone.swift in Sources */, + C2ED3A761DDE2493001071FF /* UIAlertController+Extension.swift in Sources */, 6DF9C2BC1C8F4FDA000710C1 /* Camera.swift in Sources */, 6DF9C2B21C8F4F45000710C1 /* LocationAlways.swift in Sources */, 3DC217D31D6EFD4A00600DFE /* MediaLibrary.swift in Sources */, diff --git a/Source/PermissionAlert.swift b/Source/PermissionAlert.swift index 8d1d45d..33b2455 100644 --- a/Source/PermissionAlert.swift +++ b/Source/PermissionAlert.swift @@ -22,6 +22,8 @@ // SOFTWARE. // +import UIKit + open class PermissionAlert { /// The permission. fileprivate let permission: Permission @@ -70,7 +72,7 @@ open class PermissionAlert { return controller } - internal init(permission: Permission) { + internal init(permission: Permission,alertClass: Permissionable.Type = UIAlertController.self) { self.permission = permission } diff --git a/Source/Permissionable.swift b/Source/Permissionable.swift new file mode 100644 index 0000000..c458149 --- /dev/null +++ b/Source/Permissionable.swift @@ -0,0 +1,15 @@ +// +// Permissionable.swift +// Permission +// +// Created by Gautier Gdx on 17/11/2016. +// Copyright © 2016 delba. All rights reserved. +// + +import UIKit + +protocol Permissionable: class { + init(title: String?, message: String?, preferredStyle: UIAlertControllerStyle) + + func addAction(title: String?, style: UIAlertActionStyle, handler: @escaping () -> Void) +} diff --git a/Source/UIAlertController+Extension.swift b/Source/UIAlertController+Extension.swift new file mode 100644 index 0000000..35ff712 --- /dev/null +++ b/Source/UIAlertController+Extension.swift @@ -0,0 +1,20 @@ +// +// UIAlertController+Extension.swift +// Permission +// +// Created by Gautier Gdx on 17/11/2016. +// Copyright © 2016 delba. All rights reserved. +// + +import UIKit + +extension UIAlertController: Permissionable { + + func addAction(title: String?, style: UIAlertActionStyle, handler: @escaping () -> Void) { + let action = UIAlertAction(title: title, style: style) { _ in + handler() + } + addAction(action) + } + +} From e266d34dd1d49db8bbec3dbdb728ad366e98381f Mon Sep 17 00:00:00 2001 From: gautier-gdx Date: Fri, 18 Nov 2016 10:47:42 +0100 Subject: [PATCH 2/7] added UIViewController extension --- Source/PermissionAlert.swift | 43 ++++++++++++------------ Source/UIAlertController+Extension.swift | 8 +++++ 2 files changed, 30 insertions(+), 21 deletions(-) diff --git a/Source/PermissionAlert.swift b/Source/PermissionAlert.swift index 33b2455..b015ce3 100644 --- a/Source/PermissionAlert.swift +++ b/Source/PermissionAlert.swift @@ -28,6 +28,9 @@ open class PermissionAlert { /// The permission. fileprivate let permission: Permission + //the alert controller class + fileprivate let alertClass: Permissionable.Type + /// The status of the permission. fileprivate var status: PermissionStatus { return permission.status } @@ -63,33 +66,33 @@ open class PermissionAlert { fileprivate var cancelActionTitle: String? fileprivate var defaultActionTitle: String? - var controller: UIAlertController { - let controller = UIAlertController(title: title, message: message, preferredStyle: .alert) + var controller: Permissionable { + let controller = alertClass.init(title: title, message: message, preferredStyle: .alert) - let action = UIAlertAction(title: cancelActionTitle, style: .default, handler: cancelHandler) - controller.addAction(action) + controller.addAction(title: cancelActionTitle, style: .default, handler: cancelHandler) return controller } - internal init(permission: Permission,alertClass: Permissionable.Type = UIAlertController.self) { + internal init(permission: Permission,alertClass: Permissionable.Type) { self.permission = permission + self.alertClass = alertClass } internal func present() { DispatchQueue.main.async { - UIApplication.shared.presentViewController(self.controller) + UIApplication.shared.presentViewController(self.controller as! UIViewController) } } - fileprivate func cancelHandler(_ action: UIAlertAction) { + fileprivate func cancelHandler() { callbacks(status) } } internal class DisabledAlert: PermissionAlert { - override init(permission: Permission) { - super.init(permission: permission) + override init(permission: Permission,alertClass: Permissionable.Type = UIAlertController.self) { + super.init(permission: permission,alertClass: alertClass) title = "\(permission) is currently disabled" message = "Please enable access to \(permission) in the Settings app." @@ -98,17 +101,16 @@ internal class DisabledAlert: PermissionAlert { } internal class DeniedAlert: PermissionAlert { - override var controller: UIAlertController { + override var controller: Permissionable { let controller = super.controller - let action = UIAlertAction(title: defaultActionTitle, style: .cancel, handler: settingsHandler) - controller.addAction(action) + controller.addAction(title: defaultActionTitle, style: .cancel, handler: settingHandler) return controller } - override init(permission: Permission) { - super.init(permission: permission) + override init(permission: Permission,alertClass: Permissionable.Type = UIAlertController.self) { + super.init(permission: permission,alertClass: alertClass) title = "Permission for \(permission) was denied" message = "Please enable access to \(permission) in the Settings app." @@ -121,7 +123,7 @@ internal class DeniedAlert: PermissionAlert { callbacks(status) } - private func settingsHandler(_ action: UIAlertAction) { + private func settingHandler() { NotificationCenter.default.addObserver(self, selector: .settingsHandler, name: .UIApplicationDidBecomeActive) if let URL = URL(string: UIApplicationOpenSettingsURLString) { @@ -131,17 +133,16 @@ internal class DeniedAlert: PermissionAlert { } internal class PrePermissionAlert: PermissionAlert { - override var controller: UIAlertController { + override var controller: Permissionable { let controller = super.controller - let action = UIAlertAction(title: defaultActionTitle, style: .cancel, handler: confirmHandler) - controller.addAction(action) + controller.addAction(title: defaultActionTitle, style: .cancel, handler: confirmHandler) return controller } - override init(permission: Permission) { - super.init(permission: permission) + override init(permission: Permission,alertClass: Permissionable.Type = UIAlertController.self) { + super.init(permission: permission,alertClass: alertClass) title = "\(Bundle.main.name) would like to access your \(permission)" message = "Please enable access to \(permission)." @@ -149,7 +150,7 @@ internal class PrePermissionAlert: PermissionAlert { confirm = "Confirm" } - fileprivate func confirmHandler(_ action: UIAlertAction) { + fileprivate func confirmHandler() { permission.requestAuthorization(callbacks) } } diff --git a/Source/UIAlertController+Extension.swift b/Source/UIAlertController+Extension.swift index 35ff712..a59e046 100644 --- a/Source/UIAlertController+Extension.swift +++ b/Source/UIAlertController+Extension.swift @@ -8,6 +8,14 @@ import UIKit + +extension UIAlertController { + + convenience init(title: String?, message: String?) { + self.init(title: title, message: message, preferredStyle: .alert) + } +} + extension UIAlertController: Permissionable { func addAction(title: String?, style: UIAlertActionStyle, handler: @escaping () -> Void) { From e1997bec7e7b61f980f8b377fa4cdae62eaf3b03 Mon Sep 17 00:00:00 2001 From: gautier-gdx Date: Fri, 18 Nov 2016 11:21:51 +0100 Subject: [PATCH 3/7] added Permissionable protocol --- Source/Permission.swift | 7 +++++-- Source/PermissionAlert.swift | 4 ++-- Source/Permissionable.swift | 2 +- Source/UIAlertController+Extension.swift | 2 +- 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/Source/Permission.swift b/Source/Permission.swift index 162dd29..90cc233 100644 --- a/Source/Permission.swift +++ b/Source/Permission.swift @@ -126,6 +126,9 @@ open class Permission: NSObject { } #endif + /// The alert Class type, conforming to Protocol Permissionable + open var alertClass: Permissionable.Type = UIAlertController.self + /// The permission domain. open let type: PermissionType @@ -200,7 +203,7 @@ open class Permission: NSObject { /// The alert when the permission was denied. open lazy var deniedAlert: PermissionAlert = { - return DeniedAlert(permission: self) + return DeniedAlert(permission: self,alertClass: self.alertClass) }() /// Determines whether to present the disabled alert. @@ -208,7 +211,7 @@ open class Permission: NSObject { /// The alert when the permission is disabled. open lazy var disabledAlert: PermissionAlert = { - return DisabledAlert(permission: self) + return DisabledAlert(permission: self,alertClass: self.alertClass) }() internal var callback: Callback? diff --git a/Source/PermissionAlert.swift b/Source/PermissionAlert.swift index b015ce3..a634c02 100644 --- a/Source/PermissionAlert.swift +++ b/Source/PermissionAlert.swift @@ -91,7 +91,7 @@ open class PermissionAlert { } internal class DisabledAlert: PermissionAlert { - override init(permission: Permission,alertClass: Permissionable.Type = UIAlertController.self) { + override init(permission: Permission,alertClass: Permissionable.Type) { super.init(permission: permission,alertClass: alertClass) title = "\(permission) is currently disabled" @@ -109,7 +109,7 @@ internal class DeniedAlert: PermissionAlert { return controller } - override init(permission: Permission,alertClass: Permissionable.Type = UIAlertController.self) { + override init(permission: Permission,alertClass: Permissionable.Type) { super.init(permission: permission,alertClass: alertClass) title = "Permission for \(permission) was denied" diff --git a/Source/Permissionable.swift b/Source/Permissionable.swift index c458149..0437568 100644 --- a/Source/Permissionable.swift +++ b/Source/Permissionable.swift @@ -8,7 +8,7 @@ import UIKit -protocol Permissionable: class { +public protocol Permissionable: class { init(title: String?, message: String?, preferredStyle: UIAlertControllerStyle) func addAction(title: String?, style: UIAlertActionStyle, handler: @escaping () -> Void) diff --git a/Source/UIAlertController+Extension.swift b/Source/UIAlertController+Extension.swift index a59e046..d4e32f3 100644 --- a/Source/UIAlertController+Extension.swift +++ b/Source/UIAlertController+Extension.swift @@ -18,7 +18,7 @@ extension UIAlertController { extension UIAlertController: Permissionable { - func addAction(title: String?, style: UIAlertActionStyle, handler: @escaping () -> Void) { + public func addAction(title: String?, style: UIAlertActionStyle, handler: @escaping () -> Void) { let action = UIAlertAction(title: title, style: style) { _ in handler() } From 4ee7f1ca86f53982d51f096d9b18adda23b74a7d Mon Sep 17 00:00:00 2001 From: gautier-gdx Date: Fri, 18 Nov 2016 13:53:45 +0100 Subject: [PATCH 4/7] add static initializer in Permissionable protocol --- Permission.xcodeproj/project.pbxproj | 8 ++++---- Source/PermissionAlert.swift | 2 +- Source/Permissionable.swift | 4 ++-- Source/UIAlertController+Extension.swift | 11 ++++------- 4 files changed, 11 insertions(+), 14 deletions(-) diff --git a/Permission.xcodeproj/project.pbxproj b/Permission.xcodeproj/project.pbxproj index 14e7139..3ae5920 100644 --- a/Permission.xcodeproj/project.pbxproj +++ b/Permission.xcodeproj/project.pbxproj @@ -32,8 +32,8 @@ 6DF9C2BE1C8F4FE5000710C1 /* Photos.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6DF9C2BD1C8F4FE5000710C1 /* Photos.swift */; }; 6DF9C2C01C8F5003000710C1 /* Events.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6DF9C2BF1C8F5003000710C1 /* Events.swift */; }; 6DF9C2C61C8F5B4C000710C1 /* Location.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6DF9C2C51C8F5B4C000710C1 /* Location.swift */; }; + C23C024F1DDF2EA100E8448A /* UIAlertController+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = C23C024E1DDF2EA100E8448A /* UIAlertController+Extension.swift */; }; C2ED3A741DDE2401001071FF /* Permissionable.swift in Sources */ = {isa = PBXBuildFile; fileRef = C2ED3A731DDE2401001071FF /* Permissionable.swift */; }; - C2ED3A761DDE2493001071FF /* UIAlertController+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = C2ED3A751DDE2493001071FF /* UIAlertController+Extension.swift */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -75,8 +75,8 @@ 6DF9C2BD1C8F4FE5000710C1 /* Photos.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Photos.swift; sourceTree = ""; }; 6DF9C2BF1C8F5003000710C1 /* Events.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Events.swift; sourceTree = ""; }; 6DF9C2C51C8F5B4C000710C1 /* Location.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Location.swift; sourceTree = ""; }; + C23C024E1DDF2EA100E8448A /* UIAlertController+Extension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIAlertController+Extension.swift"; sourceTree = ""; }; C2ED3A731DDE2401001071FF /* Permissionable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Permissionable.swift; sourceTree = ""; }; - C2ED3A751DDE2493001071FF /* UIAlertController+Extension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIAlertController+Extension.swift"; sourceTree = ""; }; D08FF2891DC3AD2900F28088 /* PermissionFlags.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = PermissionFlags.xcconfig; sourceTree = ""; }; /* End PBXFileReference section */ @@ -128,8 +128,8 @@ 6D0069B31C1868E8002FDB42 /* PermissionSet.swift */, 6D491E771C9CA90B00611006 /* PermissionStatus.swift */, 6D491E751C9CA7DE00611006 /* PermissionType.swift */, + C23C024E1DDF2EA100E8448A /* UIAlertController+Extension.swift */, C2ED3A731DDE2401001071FF /* Permissionable.swift */, - C2ED3A751DDE2493001071FF /* UIAlertController+Extension.swift */, ); path = Source; sourceTree = ""; @@ -295,6 +295,7 @@ buildActionMask = 2147483647; files = ( 6D491E781C9CA90B00611006 /* PermissionStatus.swift in Sources */, + C23C024F1DDF2EA100E8448A /* UIAlertController+Extension.swift in Sources */, 6D935F5F1C9A14AB00BB39E3 /* Motion.swift in Sources */, 6D935F5D1C9A0FEA00BB39E3 /* Bluetooth.swift in Sources */, 6DF9C2B81C8F4F8F000710C1 /* Notifications.swift in Sources */, @@ -312,7 +313,6 @@ 3D42A7DB1D5F66B300236ABA /* SpeechRecognizer.swift in Sources */, 6DF9C2BE1C8F4FE5000710C1 /* Photos.swift in Sources */, 6DF9C2BA1C8F4FAC000710C1 /* Microphone.swift in Sources */, - C2ED3A761DDE2493001071FF /* UIAlertController+Extension.swift in Sources */, 6DF9C2BC1C8F4FDA000710C1 /* Camera.swift in Sources */, 6DF9C2B21C8F4F45000710C1 /* LocationAlways.swift in Sources */, 3DC217D31D6EFD4A00600DFE /* MediaLibrary.swift in Sources */, diff --git a/Source/PermissionAlert.swift b/Source/PermissionAlert.swift index a634c02..5e34444 100644 --- a/Source/PermissionAlert.swift +++ b/Source/PermissionAlert.swift @@ -67,7 +67,7 @@ open class PermissionAlert { fileprivate var defaultActionTitle: String? var controller: Permissionable { - let controller = alertClass.init(title: title, message: message, preferredStyle: .alert) + let controller = alertClass.alertController(title: title, message: message, type: self.type, status: self.status) controller.addAction(title: cancelActionTitle, style: .default, handler: cancelHandler) diff --git a/Source/Permissionable.swift b/Source/Permissionable.swift index 0437568..d8086f5 100644 --- a/Source/Permissionable.swift +++ b/Source/Permissionable.swift @@ -8,8 +8,8 @@ import UIKit -public protocol Permissionable: class { - init(title: String?, message: String?, preferredStyle: UIAlertControllerStyle) +public protocol Permissionable: class { + static func alertController(title: String?,message: String?,type: PermissionType,status: PermissionStatus) -> Permissionable func addAction(title: String?, style: UIAlertActionStyle, handler: @escaping () -> Void) } diff --git a/Source/UIAlertController+Extension.swift b/Source/UIAlertController+Extension.swift index d4e32f3..99e4c45 100644 --- a/Source/UIAlertController+Extension.swift +++ b/Source/UIAlertController+Extension.swift @@ -9,14 +9,12 @@ import UIKit -extension UIAlertController { +extension UIAlertController: Permissionable { - convenience init(title: String?, message: String?) { - self.init(title: title, message: message, preferredStyle: .alert) + public static func alertController(title: String?,message: String?,type: PermissionType,status: PermissionStatus) -> Permissionable { + let alertViewController = UIAlertController(title: title, message: message, preferredStyle: .alert) + return alertViewController } -} - -extension UIAlertController: Permissionable { public func addAction(title: String?, style: UIAlertActionStyle, handler: @escaping () -> Void) { let action = UIAlertAction(title: title, style: style) { _ in @@ -24,5 +22,4 @@ extension UIAlertController: Permissionable { } addAction(action) } - } From b8995ce35ea37327c53c7d062829e854fd4985b6 Mon Sep 17 00:00:00 2001 From: gautier-gdx Date: Fri, 18 Nov 2016 15:07:19 +0100 Subject: [PATCH 5/7] debug --- Source/PermissionAlert.swift | 1 + 1 file changed, 1 insertion(+) diff --git a/Source/PermissionAlert.swift b/Source/PermissionAlert.swift index 5e34444..0719976 100644 --- a/Source/PermissionAlert.swift +++ b/Source/PermissionAlert.swift @@ -67,6 +67,7 @@ open class PermissionAlert { fileprivate var defaultActionTitle: String? var controller: Permissionable { + print("alertClass in permission \(alertClass)") let controller = alertClass.alertController(title: title, message: message, type: self.type, status: self.status) controller.addAction(title: cancelActionTitle, style: .default, handler: cancelHandler) From d31e9def1a8483336d3a85719e409bbb2b6fed93 Mon Sep 17 00:00:00 2001 From: gautier-gdx Date: Fri, 18 Nov 2016 15:19:28 +0100 Subject: [PATCH 6/7] fixed: custom alertClass was ignored in prePermission alert type --- Source/Permission.swift | 2 +- Source/PermissionAlert.swift | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/Source/Permission.swift b/Source/Permission.swift index 90cc233..4044697 100644 --- a/Source/Permission.swift +++ b/Source/Permission.swift @@ -195,7 +195,7 @@ open class Permission: NSObject { /// The pre-permission alert. open lazy var prePermissionAlert: PermissionAlert = { - return PrePermissionAlert(permission: self) + return PrePermissionAlert(permission: self,alertClass: self.alertClass) }() /// Determines whether to present the denied alert. diff --git a/Source/PermissionAlert.swift b/Source/PermissionAlert.swift index 0719976..e7f7481 100644 --- a/Source/PermissionAlert.swift +++ b/Source/PermissionAlert.swift @@ -67,7 +67,6 @@ open class PermissionAlert { fileprivate var defaultActionTitle: String? var controller: Permissionable { - print("alertClass in permission \(alertClass)") let controller = alertClass.alertController(title: title, message: message, type: self.type, status: self.status) controller.addAction(title: cancelActionTitle, style: .default, handler: cancelHandler) @@ -142,7 +141,7 @@ internal class PrePermissionAlert: PermissionAlert { return controller } - override init(permission: Permission,alertClass: Permissionable.Type = UIAlertController.self) { + override init(permission: Permission,alertClass: Permissionable.Type) { super.init(permission: permission,alertClass: alertClass) title = "\(Bundle.main.name) would like to access your \(permission)" From 6fcba8817266d614e86897c456320f9e19a60e61 Mon Sep 17 00:00:00 2001 From: gautier-gdx Date: Fri, 18 Nov 2016 17:10:04 +0100 Subject: [PATCH 7/7] cleaning --- Source/Permission.swift | 6 +++--- Source/PermissionAlert.swift | 16 ++++++++-------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/Source/Permission.swift b/Source/Permission.swift index 4044697..ae55590 100644 --- a/Source/Permission.swift +++ b/Source/Permission.swift @@ -195,7 +195,7 @@ open class Permission: NSObject { /// The pre-permission alert. open lazy var prePermissionAlert: PermissionAlert = { - return PrePermissionAlert(permission: self,alertClass: self.alertClass) + return PrePermissionAlert(permission: self) }() /// Determines whether to present the denied alert. @@ -203,7 +203,7 @@ open class Permission: NSObject { /// The alert when the permission was denied. open lazy var deniedAlert: PermissionAlert = { - return DeniedAlert(permission: self,alertClass: self.alertClass) + return DeniedAlert(permission: self) }() /// Determines whether to present the disabled alert. @@ -211,7 +211,7 @@ open class Permission: NSObject { /// The alert when the permission is disabled. open lazy var disabledAlert: PermissionAlert = { - return DisabledAlert(permission: self,alertClass: self.alertClass) + return DisabledAlert(permission: self) }() internal var callback: Callback? diff --git a/Source/PermissionAlert.swift b/Source/PermissionAlert.swift index e7f7481..edd108f 100644 --- a/Source/PermissionAlert.swift +++ b/Source/PermissionAlert.swift @@ -74,9 +74,9 @@ open class PermissionAlert { return controller } - internal init(permission: Permission,alertClass: Permissionable.Type) { + internal init(permission: Permission) { self.permission = permission - self.alertClass = alertClass + self.alertClass = permission.alertClass } internal func present() { @@ -91,8 +91,8 @@ open class PermissionAlert { } internal class DisabledAlert: PermissionAlert { - override init(permission: Permission,alertClass: Permissionable.Type) { - super.init(permission: permission,alertClass: alertClass) + override init(permission: Permission) { + super.init(permission: permission) title = "\(permission) is currently disabled" message = "Please enable access to \(permission) in the Settings app." @@ -109,8 +109,8 @@ internal class DeniedAlert: PermissionAlert { return controller } - override init(permission: Permission,alertClass: Permissionable.Type) { - super.init(permission: permission,alertClass: alertClass) + override init(permission: Permission) { + super.init(permission: permission) title = "Permission for \(permission) was denied" message = "Please enable access to \(permission) in the Settings app." @@ -141,8 +141,8 @@ internal class PrePermissionAlert: PermissionAlert { return controller } - override init(permission: Permission,alertClass: Permissionable.Type) { - super.init(permission: permission,alertClass: alertClass) + override init(permission: Permission) { + super.init(permission: permission) title = "\(Bundle.main.name) would like to access your \(permission)" message = "Please enable access to \(permission)."