Blame view

Pods/swiftScan/Source/LBXPermissions.swift 2.09 KB
582f536d   yangbin   common:2022.1.28
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
  //
  //  LBXPermissions.swift
  //  swiftScan
  //
  //  Created by xialibing on 15/12/15.
  //  Copyright © 2015 xialibing. All rights reserved.
  //
  
  import UIKit
  import AVFoundation
  import Photos
  import AssetsLibrary
  
  
  
  class LBXPermissions: NSObject {
  
      //MARK: ----获取相册权限
      static func authorizePhotoWith(comletion: @escaping (Bool) -> Void) {
          let granted = PHPhotoLibrary.authorizationStatus()
          switch granted {
          case PHAuthorizationStatus.authorized:
              comletion(true)
          case PHAuthorizationStatus.denied, PHAuthorizationStatus.restricted:
              comletion(false)
          case PHAuthorizationStatus.notDetermined:
              PHPhotoLibrary.requestAuthorization({ status in
                  DispatchQueue.main.async {
                      comletion(status == PHAuthorizationStatus.authorized)
                  }
              })
          case .limited:
              comletion(true)
          @unknown default:
              comletion(false)
          }
      }
      
      //MARK: ---相机权限
      static func authorizeCameraWith(completion: @escaping (Bool) -> Void) {
          let granted = AVCaptureDevice.authorizationStatus(for: AVMediaType.video)
          switch granted {
          case .authorized:
              completion(true)
          case .denied:
              completion(false)
          case .restricted:
              completion(false)
          case .notDetermined:
              AVCaptureDevice.requestAccess(for: AVMediaType.video, completionHandler: { (granted: Bool) in
                  DispatchQueue.main.async {
                      completion(granted)
                  }
              })
          @unknown default:
              completion(false)
          }
      }
      
      //MARK: 跳转到APP系统设置权限界面
      static func jumpToSystemPrivacySetting() {
          guard let appSetting = URL(string: UIApplication.openSettingsURLString) else {
              return
          }
          if #available(iOS 10, *) {
              UIApplication.shared.open(appSetting, options: [:], completionHandler: nil)
          } else {
              UIApplication.shared.openURL(appSetting)
          }
      }
      
  }