Skip to content

Instantly share code, notes, and snippets.

@gaelfoppolo
Created September 25, 2016 22:33
Show Gist options
  • Save gaelfoppolo/e4ba47215ca46411f71eadcf6ccf6841 to your computer and use it in GitHub Desktop.
Save gaelfoppolo/e4ba47215ca46411f71eadcf6ccf6841 to your computer and use it in GitHub Desktop.
private func askForSpeechRecognitionPermissions() {
SFSpeechRecognizer.requestAuthorization { authStatus in
var enabled: Bool = false
var message: String?
switch authStatus {
case .authorized:
enabled = true
case .denied:
enabled = false
message = "User denied access to speech recognition"
case .restricted:
enabled = false
message = "Speech recognition restricted on this device"
case .notDetermined:
enabled = false
message = "Speech recognition not yet authorized"
}
/* The callback may not be called on the main thread. Add an operation to the main queue if you want to perform action on UI. */
OperationQueue.main.addOperation {
// here you can perform UI action, e.g. enable or disable a record button
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment