Swiftpack.co - Package - SoolyChristy/PermissionDirector

说明

  • 请求从未询问的权限会弹出系统的权限窗口
  • 请求用户曾经拒绝的权限会展示弹窗提示用户,用户选择同意则跳入系统设置由用户手动打开此权限

效果

Carthage

cartfile添加

github "SoolyChristy/PermissionDirector"

Swift Package Manager

两种方式

  • package.swift添加
dependencies: [
    .package(url: "https://github.com/SoolyChristy/PermissionDirector.git", from: "0.0.4")
]
  • 在Xcode11中的PROJECT - Swift Packages 添加

使用

if !PermissionDirector.isAuthorized(for: .camera) {
  PermissionDirector.requestAuthorization(for: .camera) { (result) in
    if result == .authorized {
      print("camera permission has been authorized")
    }
  }
}

自定义弹窗

  • 自定义UIView实现PermissionAlertProtocol协议
public protocol PermissionAlertProtocol: class {
  /// 提供弹窗实例
  ///
  /// - Parameter type: 权限类型
  /// - Returns: 弹窗实例
  init(type: PermissionType)

  /// 展示弹窗
  func show()
  }
class PermissionHudView: UIView, PermissionAlertProtocol {
  required init(type: PermissionType) {
    super.init(frame: CGRect())
    // 你的实现
  }

  func show() {
    // 你的实现
  }
}
  • 更改弹窗类型
PermissionDirector.alertType = PermissionHudView.self

Github

link
Stars: 16
Help us keep the lights on

Dependencies

Used By

Total: 0

Releases

0.0.4 - Jun 11, 2019

0.0.3 - Jun 8, 2019

0.0.2 - Mar 29, 2019

0.0.1 - Mar 29, 2019