Created
August 7, 2017 05:38
-
-
Save jumbo-in-Jap/948754b7a315571bbe0e0ac726117bf7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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