Commit 77419eda authored by pete谢兆麟's avatar pete谢兆麟

添加相机授权 取消事件

parent ec99bfa8
......@@ -17,6 +17,7 @@
import UIKit
import Alamofire
import Photos
class YHImagePickerView: UIView {
var backImage: ((UIImage) -> Void)?
......@@ -164,6 +165,7 @@ class YHImagePickerView: UIView {
}
@objc func takePhoto() {
guard getPhotoLibraryAuthorization() else { return }
if UIImagePickerController.isSourceTypeAvailable(.camera){
//创建图片控制器
let imagePicker = UIImagePickerController()
......@@ -183,6 +185,7 @@ class YHImagePickerView: UIView {
}
@objc func selectPhoto() {
guard getPhotoLibraryAuthorization() else { return }
if UIImagePickerController.isSourceTypeAvailable(.photoLibrary){
let imagePicker = UIImagePickerController()
imagePicker.delegate = self
......@@ -192,6 +195,28 @@ class YHImagePickerView: UIView {
UIViewController.current?.present(imagePicker,animated: true)
}
}
private func getPhotoLibraryAuthorization() -> Bool {
let authorizationStatus = PHPhotoLibrary.authorizationStatus()
switch authorizationStatus {
case .authorized:
print("已经授权")
return true
case .notDetermined:
print("不确定是否授权")
// 请求授权
PHPhotoLibrary.requestAuthorization({ (status) in })
case .denied:
print("拒绝授权")
case .restricted:
print("限制授权")
break
case .limited: break
@unknown default:
break
}
return false
}
}
extension YHImagePickerView: UIGestureRecognizerDelegate {
......@@ -219,7 +244,7 @@ extension YHImagePickerView: UINavigationControllerDelegate, UIImagePickerContro
}
func imagePickerControllerDidCancel(_ picker: UIImagePickerController) {
picker.dismiss(animated: true, completion: nil)
}
//原生上传
......
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