我写了以下代码:
DispatchQueue.main.async {
self.cameraManager.checkForCameraAuthorization(deniedCallback: {
self.presentDeniedAlert()
self.activityIndicator.stopAnimating()
}) {
self.cameraAccess = true
self.cameraButton.isEnabled = false
self.activityIndicator.stopAnimating()
}
}
和
cameraManager.checkForMicrophoneAuthorization(deniedCallback: {
self.presentDeniedAlert()
self.activityIndicator.stopAnimating()
}) {
DispatchQueue.main.async {
self.microphoneAccess = true
self.microphoneButton.isEnabled = false
self.activityIndicator.stopAnimating()
}
}
}
(区别在于调用 async 的位置)
1.崩溃self.cameraButton.isEnabled = false can only be called from main thread
2.一个完成就好了。
有人可以解释一下,为什么会这样?