The "IntentHandler" type does not conform to the "INStartAudioCallIntentHandling" protocol

Im using INStartAudioCallIntentHandling in swift 2.3 and Im getting this error:

Type ‘IntentHandler’ does not conform to protocol ‘INStartAudioCallIntentHandling’

      

Im using Xcode 8.2.1. I put the method func handle(startAudioCall intent: INStartAudioCallIntent, completion: (INStartAudioCallIntentResponse) -> Void)

in a class. Why am I getting this error. Please help me.

+3


source to share


2 answers


you should probably also add

func confirm(start​Audio​Call:​ INStart​Audio​Call​Intent, completion:​ (INStart​Audio​Call​Intent​Response) -> Void)

      

and



func resolve​Contacts(for​Start​Audio​Call:​ INStart​Audio​Call​Intent, with:​ ([INPerson​Resolution​Result]) -> Void)

      

Use INStart Audio Call Intent Handling protocol methods to allow, acknowledge, and process audio-only call start requests with designated users. Adopt this protocol in your intent object is an extension that is capable of validating call information.

source

0


source


Swift 3.1 solution.

We pass this activity using Info, which is inferred from the display name of the contacts. I'll need to tell you who I'm going to call.

I have this simple array representing a layout database. Perhaps your application has a list of users that has all their contact details and you can check those contacts for information that was passed to resolveContacts. The user says he wants to call Dave, I'm sure it's in the database and if so, then I call Dave. And in order to make a call, you need an INPerson, which requires a personHandle, which is basically a unique identifier for a person.



You can use an email address or a phone number. I decided to go with the phone number right here. If it has a matching name, it creates this INPersonHandle, passes it as a person with that phone number and whatever name matches my existing contacts, and then I say the completion is done with that person. If there is no matching contact, we fall back to the user saying that we want a value.

import Intents

class IntentHandler: INExtension,INStartAudioCallIntentHandling {
    override func handler(for intent: INIntent) -> Any? {
        return self
    }
    func handle(startAudioCall intent: INStartAudioCallIntent, completion: @escaping (INStartAudioCallIntentResponse) -> Void) {
        print("handle")
        let ua = NSUserActivity(activityType: "Call")
        let person:String = intent.contacts![0].displayName
        ua.userInfo = ["person":person]
        completion(INStartAudioCallIntentResponse(code: .continueInApp, userActivity: ua))
    }

    func confirm(startAudioCall intent: INStartAudioCallIntent, completion: @escaping (INStartAudioCallIntentResponse) -> Void) {
        completion(INStartAudioCallIntentResponse(code: .ready, userActivity: nil))
    }

    func resolveContacts(forStartAudioCall intent: INStartAudioCallIntent, with completion: @escaping ([INPersonResolutionResult]) -> Void) {
        print("resolveContacts")
        let contacts:[String] = ["Dave","James","Herman"]
        for contact in contacts {
            if intent.contacts?[0].spokenPhrase?.uppercased() == contact.uppercased() {
                let personHandle:INPersonHandle = INPersonHandle(value: "1-555-555-5555", type: .phoneNumber)
                let person:INPerson = INPerson(personHandle: personHandle, nameComponents: nil, displayName: contact, image: nil, contactIdentifier: nil, customIdentifier: nil)
                completion([INPersonResolutionResult.success(with: person)])
                return
            }
        }
        completion([INPersonResolutionResult.needsValue()])
    }

}

      

0


source







All Articles