Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save akdsouza/bf19cd20d512ad1b8c16fcd389fd626c to your computer and use it in GitHub Desktop.
Save akdsouza/bf19cd20d512ad1b8c16fcd389fd626c to your computer and use it in GitHub Desktop.
import Intents
class IntentHandler: INExtension, INStartAudioCallIntentHandling {
func handle(intent: INStartAudioCallIntent, completion: @escaping (INStartAudioCallIntentResponse) -> Void) {
let userActivity = NSUserActivity(activityType: NSStringFromClass(INStartAudioCallIntent.self))
let response = INStartAudioCallIntentResponse(code: .continueInApp, userActivity: userActivity)
completion(response)
}
func resolveContacts(for intent: INStartAudioCallIntent, with completion: @escaping ([INPersonResolutionResult]) -> Void) {
var contactName: String?
if let contacts = intent.contacts {
contactName = contacts.first?.displayName
}
DataManager.sharedManager.findContact(contactName: contactName, with: { (contacts) in
switch contacts.count {
case 1:
completion([INPersonResolutionResult.success(with: contacts.first!)])
case 2 ... Int.max:
completion([INPersonResolutionResult.disambiguation(with: contacts)])
default:
completion([INPersonResolutionResult.unsupported()])
}
})
}
func confirm(intent: INStartAudioCallIntent, completion: @escaping (INStartAudioCallIntentResponse) -> Void) {
let userActivity = NSUserActivity(activityType: NSStringFromClass(INStartAudioCallIntent.self))
let response = INStartAudioCallIntentResponse(code: .ready, userActivity: userActivity)
completion(response)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment