Skip to content

cp3hnu/RxPrivacyManager

Repository files navigation

RxPrivacyManager

Privacy manager for iOS based on RxSwift

Currently supported:

  • Camera
  • Photos
  • Location Services
  • Microphone
  • Contacts
  • Speech

Each has a framework that you can add separately to your project.

Usage

Before, to take photo like this.

func buttonTapped() {
  let status = AVCaptureDevice.authorizationStatus(for: .video)
  switch status {
  case .notDetermined:
   AVCaptureDevice.requestAccess(
     for: AVMediaType.video,
     completionHandler: { granted in
       if granted {
         onMainThread {
           takePhoto()
         }
       } else {
         presentAlertController()
       }
     })
  case .authorized:
    takePhoto()
  default:
    presentAlertController()
  }
}

/// To open camera permission
func presentAlertController() {
  let alert = UIAlertController(title: title, message: message, preferredStyle: .alert)
  let cancelAction = UIAlertAction(title: "Cancel", style: .cancel) { _ in
    // ...
  }
  let settingAction = UIAlertAction(title: "Setting", style: .default) { _ in
    if let settingsUrl = URL(string: UIApplication.openSettingsURLString) {
      UIApplication.shared.openURL(settingsUrl)
    }
  }
  alert.addAction(cancelAction)
  alert.addAction(settingAction)
  alert.preferredAction = settingAction
  present(alert, animated: true, completion: nil)
}

Now, just a function. It's so easy!!!

import PrivacyManager
import PrivacyPhoto

let controller = ...
PrivacyManager.shared.cameraPermission(presenting: controller, authorized: {
  takePhoto()
})

Screenshot

For the first time

Without authorization

Installation

Carthage

github "cp3hnu/PrivacyManager"
  • Drag and drop PrivacyManager.framework, PrivacyPhoto.framework or other related framework from /Carthage/Build/iOS/ to Linked Frameworks and Libraries in Xcode (Project>Target>General>Linked Frameworks and Libraries)
  • Add new run script
/usr/local/bin/carthage copy-frameworks
  • Add Input files
$(SRCROOT)/Carthage/Build/iOS/PrivacyManager.framework
$(SRCROOT)/Carthage/Build/iOS/PrivacyPhoto.framework
...
other related framework

Swift Package

File -> Swift Packages -> Add Package Dependency, then search rxprivacymanager or input https://github.com/cp3hnu/RxPrivacyManager.git.

Dependencies

Requirements

  • Swift 5.0
  • Xcode 10.0
  • iOS 9+ or iOS 10+(with Speech )

License

Released under the MIT license. See LICENSE for details.