LBXPermissions.swift 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. }
  29. }
  30. //MARK: ---相机权限
  31. static func authorizeCameraWith(comletion:@escaping (Bool)->Void )
  32. {
  33. let granted = AVCaptureDevice.authorizationStatus(for: AVMediaType.video);
  34. switch granted {
  35. case .authorized:
  36. comletion(true)
  37. break;
  38. case .denied:
  39. comletion(false)
  40. break;
  41. case .restricted:
  42. comletion(false)
  43. break;
  44. case .notDetermined:
  45. AVCaptureDevice.requestAccess(for: AVMediaType.video, completionHandler: { (granted:Bool) in
  46. DispatchQueue.main.async {
  47. comletion(granted)
  48. }
  49. })
  50. }
  51. }
  52. //MARK:跳转到APP系统设置权限界面
  53. static func jumpToSystemPrivacySetting()
  54. {
  55. let appSetting = URL(string:UIApplication.openSettingsURLString)
  56. if appSetting != nil
  57. {
  58. if #available(iOS 10, *) {
  59. UIApplication.shared.open(appSetting!, options: [:], completionHandler: nil)
  60. }
  61. else{
  62. UIApplication.shared.openURL(appSetting!)
  63. }
  64. }
  65. }
  66. }