1.相机权限
//相机弹框
AVCaptureDevice.requestAccess(for: .video) { (enable) in
}
//相机是否授权
letcaptureStatus =AVCaptureDevice.authorizationStatus(for: .video)
switchcaptureStatus {
case.authorized://批准
case .notDetermined://用户从未对象授权做操作
case.denied://用户禁止
default:// 受限制的
}
2.相册权限
//弹出相册权限
PHPhotoLibrary.requestAuthorization { (enable) in
}
//相册是否授权
letstatus = PHPhotoLibrary.authorizationStatus()
switch status {
case .notDetermined://用户从未对象授权做操作
case.denied://用户禁止
default:// 受限制的
}
3.定位权限
//弹出定位权限
static var manager : CLLocationManager = CLLocationManager()
manager.requestWhenInUseAuthorization()
//定位是否授权
let authStatus = CLLocationManager.authorizationStatus()
switch authStatus {
case .notDetermined://用户从未对象授权做操作
case.denied://用户禁止
default:// 受限制的
}
4.通讯录权限
static var storeManager :CNContactStore = CNContactStore()
//通讯录权限弹框
storeManager.requestAccess(for: .contacts) { (enable, error:Error?)in
}
//通讯录是否授权
let status = CNContactStore.authorizationStatus(for: CNEntityType.contacts)
if status == CNAuthorizationStatus.authorized{//批准
}else if status == CNAuthorizationStatus.notDetermined{//用户尚未对该应用程序作出
}else if status == .denied{//拒绝
}else if status == .restricted{//被限制
}