LBXPermissions.swift 2.1 KB

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