diff --git a/PermissionScope.podspec b/PermissionScope.podspec index 8bebad0..8bfedb2 100644 --- a/PermissionScope.podspec +++ b/PermissionScope.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'PermissionScope' - s.version = '1.1.1' + s.version = '1.1.2' s.license = 'MIT' s.summary = 'A Periscope-inspired way to ask for iOS permissions' s.homepage = 'https://github.com/nickoneill/PermissionScope' diff --git a/PermissionScope/PermissionScope.swift b/PermissionScope/PermissionScope.swift index bda5037..0d8e088 100644 --- a/PermissionScope/PermissionScope.swift +++ b/PermissionScope/PermissionScope.swift @@ -19,6 +19,7 @@ import Contacts public typealias statusRequestClosure = (_ status: PermissionStatus) -> Void public typealias authClosureType = (_ finished: Bool, _ results: [PermissionResult]) -> Void public typealias cancelClosureType = (_ results: [PermissionResult]) -> Void +public typealias dismissedClosureType = (_ canceled: Bool) -> Void typealias resultsForConfigClosure = ([PermissionResult]) -> Void @objc public class PermissionScope: UIViewController, CLLocationManagerDelegate, UIGestureRecognizerDelegate, CBPeripheralManagerDelegate { @@ -93,9 +94,11 @@ typealias resultsForConfigClosure = ([PermissionResult]) -> Void // Useful for direct use of the request* methods /// Callback called when permissions status change. - public var onAuthChange: authClosureType? = nil + public var onAuthChange: authClosureType? = nil /// Callback called when the user taps on the close button. - public var onCancel: cancelClosureType? = nil + public var onCancel: cancelClosureType? = nil + /// Callback called when the controller is dismissed + public var onDismiss: dismissedClosureType? = nil /// Called when the user has disabled or denied access to notifications, and we're presenting them with a help dialog. public var onDisabledOrDenied: cancelClosureType? = nil @@ -103,7 +106,7 @@ typealias resultsForConfigClosure = ([PermissionResult]) -> Void public var viewControllerForAlerts : UIViewController? /** - Checks whether all the configured permission are authorized or not. + Checks whether all the configured permissions are authorized or not. - parameter completion: Closure used to send the result of the check. */ @@ -117,7 +120,7 @@ typealias resultsForConfigClosure = ([PermissionResult]) -> Void } /** - Checks whether all the required configured permission are authorized or not. + Checks whether all the required configured permissions are authorized or not. **Deprecated** See issues #50 and #51. - parameter completion: Closure used to send the result of the check. @@ -996,11 +999,12 @@ typealias resultsForConfigClosure = ([PermissionResult]) -> Void - parameter authChange: Called when a status is detected on any of the permissions. - parameter cancelled: Called when the user taps the Close button. */ - @objc public func show(_ authChange: authClosureType? = nil, cancelled: cancelClosureType? = nil) { + @objc public func show(_ authChange: authClosureType? = nil, cancelled: cancelClosureType? = nil, dismissed: dismissedClosureType? = nil) { assert(!configuredPermissions.isEmpty, "Please add at least one permission") onAuthChange = authChange onCancel = cancelled + onDismiss = dismissed DispatchQueue.main.async { while self.waitingForBluetooth || self.waitingForMotion { } @@ -1073,7 +1077,7 @@ typealias resultsForConfigClosure = ([PermissionResult]) -> Void /** Hides the modal viewcontroller with an animation. */ - public func hide() { + public func hide(canceled: Bool = false) { let window = UIApplication.shared.keyWindow! DispatchQueue.main.async(execute: { @@ -1081,6 +1085,9 @@ typealias resultsForConfigClosure = ([PermissionResult]) -> Void self.baseView.frame.origin.y = window.center.y + 400 self.view.alpha = 0 }, completion: { finished in + if let onDismiss = self.onDismiss { + onDismiss(canceled) + } self.view.removeFromSuperview() }) }) @@ -1120,7 +1127,7 @@ typealias resultsForConfigClosure = ([PermissionResult]) -> Void Called when the users taps on the close button. */ func cancel() { - self.hide() + self.hide(canceled: true) if let onCancel = onCancel { getResultsForConfig({ results in diff --git a/README.md b/README.md index 03fc960..659aceb 100644 --- a/README.md +++ b/README.md @@ -89,6 +89,8 @@ class ViewController: UIViewController { print("got results \(results)") }, cancelled: { (results) -> Void in print("thing was cancelled") + }, dismissed: { canceled in + print("the controller was dismissed") }) } } @@ -157,17 +159,20 @@ You will probably also want to set the `onAuthChange`, `onCancel`, and `onDisabl ```swift pscope.onAuthChange = { (finished, results) in - println("Request was finished with results \(results)") + print("Request was finished with results \(results)") if results[0].status == .Authorized { - println("They've authorized the use of notifications") + print("They've authorized the use of notifications") UIApplication.sharedApplication().registerForRemoteNotifications() } } pscope.onCancel = { results in - println("Request was cancelled with results \(results)") + print("Request was cancelled with results \(results)") } pscope.onDisabledOrDenied = { results in - println("Request was denied or disabled with results \(results)") + print("Request was denied or disabled with results \(results)") +} +pscope.onDismissed = { canceled in + print("The controller was dismissed by cancel action = \(canceled)") } ```