AllowX 1.1.2

AllowX 1.1.2

Karim Ebrahem维护。




AllowX 1.1.2

AllowX

Cocoapod Version MIT License
Facebook: @KarimEbrahemAbdelaziz Twitter: @k_ebrahem_

AllowX通过带有出色权限请求对话框,向iOS提供统一的API来请求权限。

屏幕截图

要求

  • Xcode 10.2+
  • Swift 5+
  • iOS 10+

安装

CocoaPods

CocoaPods是一个用于Cocoa项目的依赖管理器。有关使用和安装说明,请访问他们的网站。要使用CocoaPods将AllowX集成到Xcode项目中,请在您的Podfile中指定它。

pod 'AllowX', '~> 1.1.2'

使用

AllowX提供配置协议AllowXConfiguration,允许您配置所有状态标题和消息。要配置权限警报,您只需创建一个符合AllowXConfiguration协议的自定义配置类即可。

class CustomCameraConfiguration: AllowXConfiguration {
    // AllowX Permission Alert Height.
    var alertHeight: EKAttributes.PositionConstraints.Edge {
        return .constant(value: 400)
    }
    
    // AllowX Permission Alert Image.
    var image: UIImage {
        return UIImage(named: "camera")!
    }
    
    // AllowX Pre-Permission Alert Title.
    var prePermissionTitle: String {
        return "Camera Permission"
    }
    
    // AllowX Denied Permission Alert Title.
    var deniedTitle: String {
        return "Camera Permission"
    }
    
    // AllowX Disabled Permission Alert Title.
    var disabledTitle: String {
        return "Camera Permission"
    }
    
    // AllowX Permission Alert Title's Font.
    var titleFont: UIFont {
        return .boldSystemFont(ofSize: 16)
    }
    
    // AllowX Permission Alert Title's Color.
    var titleColor: UIColor {
        return .darkGray
    }
    
    // AllowX Pre-Permission Alert Message.
    var prePermissionMessage: String {
        return "Please, To scan codes, allow us to access your camera"
    }
    
    // AllowX Denied Permission Alert Message.
    var deniedMessage: String {
        return "Please, To scan codes, allow us to access your camera"
    }
    
    // AllowX Disabled Permission Alert Message.
    var disabledMessage: String {
        return "Please, To scan codes, allow us to access your camera"
    }
    
    // AllowX Permission Alert Message's Font.
    var messageFont: UIFont {
        return .systemFont(ofSize: 16)
    }
    
    // AllowX Permission Alert Message's Color.
    var messageColor: UIColor {
        return .gray
    }
    
    // AllowX Permission Alert Cancel Button's Title.
    var cancelButtonTitle: String {
        return "Cancel"
    }
    
    // AllowX Permission Alert Not Now Button's Title.
    var notNowButtonTitle: String {
        return "Not Now"
    }
    
    // AllowX Permission Alert Go to Settings Button's Title.
    var goToSettingsButtonTitle: String {
        return "Go to Settings"
    }
    
    // AllowX Permission Alert Confirm Button's Title.
    var confirmButtonTitle: String {
        return "Allow"
    }
    
    // AllowX Permission Dialog Button Title's Font.
    var buttonTitleFont: UIFont {
        return .systemFont(ofSize: 16)
    }
    
    // Control if you want to present Pre-Premission Alert.
    var presentPrePermissionAlert: Bool {
        return true
    }
    
    // Control if you want to present Denied Alert.
    var presentDeniedAlert: Bool {
        return true
    }
    
    // Control if you want to present Disabled Alert.
    var presentDisabledAlert: Bool {
        return true
    }
}

使用配置初始化AllowX权限。(每个权限都有默认配置值)

// Create AllowX Camera Permission Configuration.
let configuration = CustomCameraConfiguration()

// AllowX Camera Permission.
let cameraPermission: AllowX = AllowX(type: .camera, configuration: configuration)

AllowX支持3种权限(目前)相机、位置和通知权限。

// AllowX Location Always Permission.
let locationAlwaysPermission: AllowX = AllowX(type: .locationAlways)

// AllowX Location While in Use Permission.
let locationWhileInUsePermission: AllowX = AllowX(type: .locationWhenInUse)

// AllowX Notifications Permission.
let notificationsPermission: AllowX = AllowX(type: .notifications([.alert, .badge, .sound]))

您可以为询问权限状态时执行的代码块指定一个。

// Ask for Premission 🔥
cameraPermission.request { status in
    switch status {
    case .authorized:    print("authorized")
    case .denied:        print("denied")
    case .disabled:      print("disabled")
    case .notDetermined: print("not determined")
    }
}

作者

Karim Ebrahem,[email protected]

许可协议

AllowX遵循MIT许可协议。有关更多信息,请参阅LICENSE文件。

如有必要,它将进行更新,并且一旦发现问题,将立即进行修复,以保持其最新状态。

祝您使用愉快!