Commit 0ceb7101 authored by Steven杜宇's avatar Steven杜宇

// 权限

parent 4b4e94a0
......@@ -90,6 +90,13 @@ class YHMyPermissionSettingVC: YHBaseViewController {
updateNetWorkStatus()
// 2)获取相册权限
requestAndUpdatePhotoPermission()
// 3)获取相机权限
requestAndUpdateCameraPermission()
}
func requestAndUpdatePhotoPermission() {
requestPhotoLibraryPermission {
[weak self] grant in
guard let self = self else { return }
......@@ -102,8 +109,9 @@ class YHMyPermissionSettingVC: YHBaseViewController {
}
}
}
}
// 3)获取相机权限
func requestAndUpdateCameraPermission() {
requestCameraPermission {
[weak self] grant in
guard let self = self else { return }
......@@ -132,13 +140,7 @@ class YHMyPermissionSettingVC: YHBaseViewController {
case .notDetermined:
// 尚未确定,请求授权
PHPhotoLibrary.requestAuthorization {
authorizationStatus in
self.requestPhotoLibraryPermission {
granted in
completion(granted)
}
}
completion(false)
@unknown default:
completion(false)
......@@ -159,10 +161,7 @@ class YHMyPermissionSettingVC: YHBaseViewController {
case .notDetermined:
// 尚未确定,请求授权
AVCaptureDevice.requestAccess(for: .video) {
granted in
completion(granted)
}
completion(false)
@unknown default:
completion(false)
......@@ -195,7 +194,33 @@ extension YHMyPermissionSettingVC: UITableViewDelegate, UITableViewDataSource {
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
if 0 <= indexPath.row && indexPath.row < items.count {
let item = items[indexPath.row]
if item.type == .photo {
let status = PHPhotoLibrary.authorizationStatus()
if status == .notDetermined {
PHPhotoLibrary.requestAuthorization {
authorizationStatus in
self.requestPhotoLibraryPermission {
[weak self] granted in
guard let self = self else { return }
requestAndUpdatePhotoPermission()
}
}
return
}
}
if item.type == .camera {
let status = AVCaptureDevice.authorizationStatus(for: .video)
if status == .notDetermined {
AVCaptureDevice.requestAccess(for: .video) {
[weak self] granted in
guard let self = self else { return }
requestAndUpdateCameraPermission()
}
return
}
}
let url = URL(string: UIApplication.openSettingsURLString)
if let url = url, UIApplication .shared.canOpenURL(url) {
printLog("settingUrl:\(url)")
......@@ -204,6 +229,7 @@ extension YHMyPermissionSettingVC: UITableViewDelegate, UITableViewDataSource {
})
}
}
}
private func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> CGFloat {
return UITableView.automaticDimension
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment