| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158 |
- import UIKit
- import CoreLocation
- import Contacts
- import AddressBook
- import EventKit
- import AssetsLibrary
- import Photos
- import CoreBluetooth
- public class HardwareAuthorization: NSObject {
- class func isAuthorizationLocation() -> Bool {
- let status = CLLocationManager.authorizationStatus()
- switch status {
- case .notDetermined:
- return true
- case .denied :
- return false
- case .restricted :
- return false
- default:
- break
- }
- return true
- }
- class func isAuthorizationAddress() -> Bool {
- if #available(iOS 9.0, *) {
- let status = CNContactStore.authorizationStatus(for: .contacts)
- switch status {
- case .notDetermined:
- return true
- case .denied :
- return false
- case .restricted :
- return false
- default:
- break
- }
- } else {
- let status = ABAddressBookGetAuthorizationStatus()
- switch status {
- case .notDetermined:
- return true
- case .denied :
- return false
- case .restricted :
- return false
- default:
- break
- }
- }
- return true
- }
- class func isAuthorizationReminders() -> Bool {
- return isAuthorizationEvent(entityType: .reminder)
- }
- class func isAuthorizationCalender() -> Bool {
- return isAuthorizationEvent(entityType: .event)
- }
- class func isAuthorizationEvent(entityType: EKEntityType) -> Bool {
- let status = EKEventStore.authorizationStatus(for: entityType)
- switch status {
- case .notDetermined:
- return true
- case .denied :
- return false
- case .restricted :
- return false
- default:
- break
- }
- return true
- }
- class func isAuthorizationPhotoAlbum() -> Bool {
- if #available(iOS 9.0, *) {
- let status = PHPhotoLibrary.authorizationStatus()
- switch status {
- case .notDetermined:
- return true
- case .denied :
- return false
- case .restricted :
- return false
- default:
- break
- }
- } else {
- let status = ALAssetsLibrary.authorizationStatus()
- switch status {
- case .notDetermined:
- return true
- case .denied :
- return false
- case .restricted :
- return false
- default:
- break
- }
- }
- return true
- }
- class func isAuthorizationBluetooth() -> Bool {
- let status = CBPeripheralManager.authorizationStatus()
- switch status {
- case .notDetermined:
- return true
- case .denied :
- return false
- case .restricted :
- return false
- default:
- break
- }
- return true
- }
- class func isAuthroizationCamera() -> Bool {
- let status = AVCaptureDevice.authorizationStatus(for: .video)
- switch status {
- case .notDetermined:
- return true
- case .denied :
- return false
- case .restricted :
- return false
- default:
- break
- }
- return true
- }
- class func isAuthroizationMicrophone() -> Bool {
- let status = AVAudioSession.sharedInstance().recordPermission.rawValue
- switch status {
- case 1:
- return true
- case 2:
- return false
- default:
- return true
- }
- }
- }
|