Skip to content

Instantly share code, notes, and snippets.

@jumbo-in-Jap
Created August 7, 2017 05:38
Show Gist options
  • Save jumbo-in-Jap/948754b7a315571bbe0e0ac726117bf7 to your computer and use it in GitHub Desktop.
Save jumbo-in-Jap/948754b7a315571bbe0e0ac726117bf7 to your computer and use it in GitHub Desktop.
// MARK: Authorized Property
var audioAuthorized = Variable<Bool>(false)
var videoAuthorized = Variable<Bool>(false)
-----
func bind(){
// どちらも許可されたら通信開始
Observable
.combineLatest(audioAuthorized.asObservable(), videoAuthorized.asObservable())
.subscribe (onNext:{ (audio, video) in
if audio && video {
DispatchQueue.main.asyncAfter(deadline: .now()) {
self.requestHogeHoge()
}
}
}).addDisposableTo(disposeBag)
}
-----
func checkAuthorize(){
let movieStatus = AVCaptureDevice.authorizationStatus(forMediaType: AVMediaTypeVideo)
let audioStatus = AVCaptureDevice.authorizationStatus(forMediaType: AVMediaTypeAudio)
if movieStatus == .authorized && audioStatus == .authorized{
}else{
UIAlertController.oneButton("レッスンの準備", message: "マイクとカメラへのアクセスを許可してください", handler: { (alert) in
AVCaptureDevice.requestAccess(forMediaType: AVMediaTypeAudio) { (granted) in
self.audioAuthorized.value = granted
}
AVCaptureDevice.requestAccess(forMediaType: AVMediaTypeVideo) { (granted) in
self.videoAuthorized.value = granted
}
})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment