Encountered the same problem. When I reproduced it again, I set a global breakpoint when connecting to a real machine for debugging, and found that the crash occurred in the frame of setting a custom alertWindow. I took a look and found that there is no null pointer in alertWindow. Then the reason is obvious. A crash occurred when operating the UI. The reason was that the UI was not operated on the main thread. Go back to the code and see the judgment of calling the camera status
let authStatus = AVCaptureDevice.authorizationStatusForMediaType(AVMediaTypeVideo)
switch authStatus {
case .NotDetermined:
AVCaptureDevice.requestAccessForMediaType(AVMediaTypeVideo, completionHandler: { (granted) in
if (granted) {
//第一次用户接受
if let tmp = handle {
tmp()
}
}else{
//用户拒绝 *** 问题在这里,如果第一次用户拒绝了,回调并不在主线程。(注意,此时的case分支在用户并未决定里)
if let tmp = limitHandle {
dispatch_async(dispatch_get_main_queue(), {
tmp()
})
}
}
})
case .Restricted: // 无法访问
dLog("没有设备")
case .Denied: // 用户拒绝
if let tmp = limitHandle {
dispatch_async(dispatch_get_main_queue(), {
tmp()
})
}
case .Authorized: // 开启授权
if let tmp = handle {
tmp()
}
}
This problem can be solved by placing the callback on the main thread where the user first decides whether to agree to use the album.
Encountered the same problem.
When I reproduced it again, I set a global breakpoint when connecting to a real machine for debugging, and found that the crash occurred in the frame of setting a custom alertWindow.
I took a look and found that there is no null pointer in alertWindow.
Then the reason is obvious. A crash occurred when operating the UI. The reason was that the UI was not operated on the main thread.
Go back to the code and see the judgment of calling the camera status
This problem can be solved by placing the callback on the main thread where the user first decides whether to agree to use the album.