Skip to content

Commit

Permalink
Update to 5.2.4
Browse files Browse the repository at this point in the history
Add permissions list in `didHide` delegate method.
  • Loading branch information
ivanvorobei committed Nov 27, 2019
1 parent fe365e3 commit d48fa7f
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 21 deletions.
45 changes: 30 additions & 15 deletions Example iOS/Controllers/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class ViewController: UITableViewController {
navigationItem.rightBarButtonItem = UIBarButtonItem.init(barButtonSystemItem: .play, target: self, action: #selector(self.requestPermissions))
tableView.register(UITableViewCell.self, forCellReuseIdentifier: "cell")
}

@objc func requestPermissions() {
if selectedPermissions.isEmpty { return }
guard let segmentControl = navigationItem.titleView as? UISegmentedControl else { return }
Expand Down Expand Up @@ -80,31 +80,46 @@ extension ViewController: SPPermissionsDataSource, SPPermissionsDelegate {
/**
Configure permission cell here.
You can return permission if want use default values.

- parameter cell: Cell for configure. You can change all data.
- parameter permission: Configure cell for it permission.
*/
func configure(_ cell: SPPermissionTableViewCell, for permission: SPPermission) -> SPPermissionTableViewCell {

/*
// Titles
cell.permissionTitleLabel.text = "Notifications"
cell.permissionDescriptionLabel.text = "Remind about payment to your bank"
cell.button.allowTitle = "Allow"
cell.button.allowedTitle = "Allowed"

// Colors
cell.iconView.color = .systemBlue
cell.button.allowedBackgroundColor = .systemBlue
cell.button.allowTitleColor = .systemBlue

// If you want set custom image.
cell.set(UIImage(named: "IMAGE-NAME")!)
*/
// Titles
cell.permissionTitleLabel.text = "Notifications"
cell.permissionDescriptionLabel.text = "Remind about payment to your bank"
cell.button.allowTitle = "Allow"
cell.button.allowedTitle = "Allowed"
// Colors
cell.iconView.color = .systemBlue
cell.button.allowedBackgroundColor = .systemBlue
cell.button.allowTitleColor = .systemBlue
// If you want set custom image.
cell.set(UIImage(named: "IMAGE-NAME")!)
*/

return cell
}

/**
Call when controller closed.

- parameter ids: Permissions ids, which using this controller.
*/
func didHide(permissions ids: [Int]) {
let permissions = ids.map { SPPermission(rawValue: $0)! }
print("Did hide with permissions: ", permissions.map { $0.name })
}

/**
Alert if permission denied. For disable alert return `nil`.
If this method not implement, alert will be show with default titles.

- parameter permission: Denied alert data for this permission.
*/
func deniedData(for permission: SPPermission) -> SPPermissionDeniedAlertData? {
if permission == .notification {
Expand Down
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -263,12 +263,18 @@ In the delegate you can implement these methods:
// Events
func didAllow(permission: SPPermission) {}
func didDenied(permission: SPPermission) {}
func didHide() {}
func didHide(permissions ids: [Int])

// Denied alert. Show alert if permission denied.
func deniedData(for permission: SPPermission) -> SPPermissionDeniedAlertData?
```

For `didHide` no way return array of `SPPermission`, becouse array of enum can't represented in objc. But you can detect permissions with it ID:

```swift
let permissions = ids.map { SPPermission(rawValue: $0) }
```

### Denied alert

If you don't want show an alert if a permission is denied, return `nil` in the delegate. You can set the text in the alert:
Expand Down
2 changes: 1 addition & 1 deletion SPPermissions.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Pod::Spec.new do |s|

s.name = "SPPermissions"
s.version = "5.2.2"
s.version = "5.2.4"
s.summary = "Ask permissions on Swift. Available List, Dialog & Native interface. Can check state permission."
s.homepage = "https://github.com/IvanVorobei/SPPermissions"
s.source = { :git => "https://github.com/IvanVorobei/SPPermissions.git", :tag => s.version }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,8 @@ public class SPPermissionsDialogController: UIViewController, SPPermissionsContr
public override func dismiss(animated flag: Bool, completion: (() -> Void)? = nil) {
super.dismiss(animated: flag, completion: {
completion?()
self.delegate?.didHide?()
let ids: [Int] = self.permissions.map { $0.rawValue }
self.delegate?.didHide?(permissions: ids)
})
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,8 @@ public class SPPermissionsListController: UITableViewController, SPPermissionsCo
public override func dismiss(animated flag: Bool, completion: (() -> Void)? = nil) {
super.dismiss(animated: flag, completion: {
completion?()
self.delegate?.didHide?()
let ids: [Int] = self.permissions.map { $0.rawValue }
self.delegate?.didHide?(permissions: ids)
})
}

Expand Down Expand Up @@ -239,7 +240,8 @@ extension SPPermissionsListController {
extension SPPermissionsListController: UIAdaptivePresentationControllerDelegate {

public func presentationControllerDidDismiss(_ presentationController: UIPresentationController) {
self.delegate?.didHide?()
let ids: [Int] = self.permissions.map { $0.rawValue }
self.delegate?.didHide?(permissions: ids)
}
}
#endif
11 changes: 10 additions & 1 deletion Source/SPPermissions/Protocols/SPPermissionsDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,30 @@ import UIKit

/**
Call when permission allowed.

- parameter permission: Which permission did allowed.
*/
@objc optional func didAllow(permission: SPPermission)

/**
Call when permission denied.

- parameter permission: Which permission did denied.
*/
@objc optional func didDenied(permission: SPPermission)

/**
Call when controller closed.

- parameter ids: IDs permissions which showed in this controller. Also include permisssions, which not requested.
No way pass array of `SPPermission` becouse array of enum can't represented in objc.
*/
@objc optional func didHide()
@objc optional func didHide(permissions ids: [Int])

/**
If permission denied, after action show alert with propose open settings and allow this permission.

- parameter permission: Denied data for this permission.
*/
@objc optional func deniedData(for permission: SPPermission) -> SPPermissionDeniedAlertData?
}

0 comments on commit d48fa7f

Please sign in to comment.