I am trying to rewrite the AVCam example from Apple in Swift. When I check if the device is authorized I want to set the property deviceAuthorized to true or false.
I get inside the block because I get "Access is granted" in my output. But when I want to check if my property is changed it still says it is false. I also tried with a local variable but this isn't working either.
What am I doing wrong?
var deviceAuthorized:Bool?
...
func checkDeviceAuthorizationStatus() -> Bool{
var mediaType = AVMediaTypeVideo
var localDeviceAuthorized:Bool = false
AVCaptureDevice.requestAccessForMediaType(mediaType, completionHandler: {
(granted:Bool) -> () in
if(granted){
println("Access is granted")
self.deviceAuthorized = true
localDeviceAuthorized = true
}else{
println("Access is not granted")
}
})
println("Acces is \(localDeviceAuthorized)")
return self.deviceAuthorized!
}