类型'IntentHandler'不符合协议'INStartAudioCallIntentHandling'

时间:2017-04-01 10:11:58

标签: ios swift2 xcode8 ios-app-extension

我在swift 2.3中使用INStartAudioCallIntentHandling,我收到此错误:

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

我正在使用Xcode 8.2.1。我将func handle(startAudioCall intent: INStartAudioCallIntent, completion: (INStartAudioCallIntentResponse) -> Void)方法放入类中。为什么我收到此错误。请帮帮我。

2 个答案:

答案 0 :(得分:0)

您可能还应该添加

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

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

使用INStart音频呼叫意图处理协议的方法   解决,确认和处理启动仅音频呼叫的请求   指定用户。在Intents的对象中采用此协议   能够验证呼叫信息的分机。

source

答案 1 :(得分:0)

Swift 3.1解决方案。

我们通过来自联系人显示名称的信息传递该用户活动。我需要说出我打电话给谁。

我有这个简单的数组,它是模拟数据库的表示。也许在您的应用程序中有某种用户列表,其中包含所有联系信息,您可以根据传递给resolveContacts的信息检查这些联系人。用户说他们想打电话给Dave,我确保数据库中有这个,如果是,那么我打电话给Dave。并且为了进行呼叫,你需要一个INPerson,它需要一个personH​​andle,它基本上是一个人的唯一标识符。

您可以使用电子邮件或电话号码。我选择在这里使用电话号码。如果它具有相应的名称,则会创建此INPersonH​​andle,将其作为具有此电话号码和任何名称的人传递,如果它与我现有的联系人匹配,然后我说该人的完成成功。如果没有匹配的联系人,那么我们会回复用户说我们需要一个值。

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()])
    }

}