import UIKit
import AVFoundation
import Photos
import CoreLocation
import Contacts
import CoreBluetooth
import EventKit
/*
默认都是 .notDetermined 用户没有做出选择
*/
class PermissionManager: NSObject {
/// 麦克风权限
/// Privacy - Microphone Usage Description
public static func isOpenMicrophone() -> Bool {
let authStatus = AVCaptureDevice.authorizationStatus(for: AVMediaType.audio)
if authStatus == .denied ||
authStatus == .restricted {
return false
}
return true
}
/// 访问相册权限
/// Privacy - Photo Library Usage Description (读取)
/// Privacy - Photo Library Additions Usage Description (写入)
public static func isOpenPhotoLibrary() -> Bool {
let authStatus = PHAuthorizationStatus.authorized
if authStatus == .denied ||
authStatus == .restricted {
return false
}
return true
}
/// 访问相机权限
/// Privacy - Camera Usage Description
public static func isOpenCamera() -> Bool {
let authStatus = AVCaptureDevice.authorizationStatus(for: .video)
if authStatus == .denied ||
authStatus == .restricted {
return false
}
return true
}
/// 推送权限
public static func isOpenPush() -> Bool {
let setting = UIApplication.shared.currentUserNotificationSettings
if setting?.types == .alert ||
setting?.types == .sound ||
setting?.types == .badge {
return true
}
return false
}
/// 定位权限
/// Privacy - Location When In Use Usage Description (使用期间)
/// Privacy - Location Always and When In Use Usage Description (总是)
public static func isOpenLocation() -> Bool {
let location = CLLocationManager.locationServicesEnabled()
if !location {
return false
}
let authStatus = CLLocationManager.authorizationStatus()
if authStatus == .denied ||
authStatus == .restricted {
return false
}
return true
}
/// 通讯录权限
/// Privacy - Contacts Usage Description
public static func isOpenContactStore() -> Bool {
let authStatus = CNContactStore.authorizationStatus(for: .contacts)
if authStatus == .denied ||
authStatus == .restricted {
return false
}
return true
}
/// 蓝牙权限
/// Privacy - Bluetooth Peripheral Usage Description
public static func isOpenBluetooth() -> Bool {
let authStatus = CBPeripheralManager.authorizationStatus()
if authStatus == .denied ||
authStatus == .restricted {
return false
}
return true
}
/// 日历权限
/// Privacy - AppleEvents Sending Usage Description
public static func isOpenEvent() -> Bool {
let authStatus = EKEventStore.authorizationStatus(for: .event)
if authStatus == .denied ||
authStatus == .restricted {
return false
}
return true
}
/// 备忘录权限
/// Privacy - Reminders Usage Description
public static func isOpenReminder() -> Bool {
let authStatus = EKEventStore.authorizationStatus(for: .reminder)
if authStatus == .denied ||
authStatus == .restricted {
return false
}
return true
}
}
访问权限
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 通过SpringSecurity动态的控制菜单的显示和隐藏 概述: 后台管理中,用户都拥有自己的角色,而角色决定了...
- Linux的文件访问权限可以使用ls -l进行查看,如下图这样操作就可以了。 一、访问权限 访问权限分为读(rea...
- 1.适用场景 在启动某个服务的时候,比如python中django启动的时候8000端口被占用,导致无法启动服务。...