LoginSignup
6
5

More than 5 years have passed since last update.

プライバシーの確認を必要なやつだけ次々出す

Last updated at Posted at 2017-12-13

「カメラロールを使用します」やらなんやらのプライバシーのアラートを一度に次々出す
毎回調べるの面倒だからまとめた
すでに出したことあるやつならスキップして次のアラートを出す

func checkAuth(_ completion:(()->())? = nil){
    //カメラロール
    func checkAuthCameraroll(_ completion:(()->())?){
      if PHPhotoLibrary.authorizationStatus() != .authorized {
        PHPhotoLibrary.requestAuthorization({ (status) in
          completion?()
        })
      }
      else{
        completion?()
      }
    }
    //ビデオ
    func checkAuthVideo(_ completion:(()->())?){
      if AVCaptureDevice.authorizationStatus(for: AVMediaType.video) != .authorized {
        AVCaptureDevice.requestAccess(for: AVMediaType.video, completionHandler: { (isSuccess) in
          completion?()
        })
      }
      else{
        completion?()
      }
    }
    //オーディオ
    func checkAuthAudio(_ completion:(()->())?){
      if AVCaptureDevice.authorizationStatus(for: AVMediaType.audio) != .authorized {
        AVCaptureDevice.requestAccess(for: AVMediaType.audio, completionHandler: { (isSuccess) in
          completion?()
        })
      }
      else{
        completion?()
      }
    }

    checkAuthCameraroll {
      checkAuthVideo {
        checkAuthAudio {
          completion?()
        }
      }
    }
  }
6
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
5