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

// 权限

parent 4b4e94a0
...@@ -90,6 +90,13 @@ class YHMyPermissionSettingVC: YHBaseViewController { ...@@ -90,6 +90,13 @@ class YHMyPermissionSettingVC: YHBaseViewController {
updateNetWorkStatus() updateNetWorkStatus()
// 2)获取相册权限 // 2)获取相册权限
requestAndUpdatePhotoPermission()
// 3)获取相机权限
requestAndUpdateCameraPermission()
}
func requestAndUpdatePhotoPermission() {
requestPhotoLibraryPermission { requestPhotoLibraryPermission {
[weak self] grant in [weak self] grant in
guard let self = self else { return } guard let self = self else { return }
...@@ -102,8 +109,9 @@ class YHMyPermissionSettingVC: YHBaseViewController { ...@@ -102,8 +109,9 @@ class YHMyPermissionSettingVC: YHBaseViewController {
} }
} }
} }
}
// 3)获取相机权限
func requestAndUpdateCameraPermission() {
requestCameraPermission { requestCameraPermission {
[weak self] grant in [weak self] grant in
guard let self = self else { return } guard let self = self else { return }
...@@ -132,13 +140,7 @@ class YHMyPermissionSettingVC: YHBaseViewController { ...@@ -132,13 +140,7 @@ class YHMyPermissionSettingVC: YHBaseViewController {
case .notDetermined: case .notDetermined:
// 尚未确定,请求授权 // 尚未确定,请求授权
PHPhotoLibrary.requestAuthorization { completion(false)
authorizationStatus in
self.requestPhotoLibraryPermission {
granted in
completion(granted)
}
}
@unknown default: @unknown default:
completion(false) completion(false)
...@@ -159,10 +161,7 @@ class YHMyPermissionSettingVC: YHBaseViewController { ...@@ -159,10 +161,7 @@ class YHMyPermissionSettingVC: YHBaseViewController {
case .notDetermined: case .notDetermined:
// 尚未确定,请求授权 // 尚未确定,请求授权
AVCaptureDevice.requestAccess(for: .video) { completion(false)
granted in
completion(granted)
}
@unknown default: @unknown default:
completion(false) completion(false)
...@@ -195,13 +194,40 @@ extension YHMyPermissionSettingVC: UITableViewDelegate, UITableViewDataSource { ...@@ -195,13 +194,40 @@ extension YHMyPermissionSettingVC: UITableViewDelegate, UITableViewDataSource {
} }
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
if 0 <= indexPath.row && indexPath.row < items.count {
let url = URL(string: UIApplication.openSettingsURLString) let item = items[indexPath.row]
if let url = url, UIApplication .shared.canOpenURL(url) { if item.type == .photo {
printLog("settingUrl:\(url)") let status = PHPhotoLibrary.authorizationStatus()
UIApplication .shared.open(url, options: [:], completionHandler: { if status == .notDetermined {
(success) in 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)")
UIApplication .shared.open(url, options: [:], completionHandler: {
(success) in
})
}
} }
} }
......
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