类型“IntentHandler”不符合协议“INStartAudioCallIntentHandling”
我使用INStartAudioCallIntentHandling在SWIFT 2.3和我得到这个错误:类型“IntentHandler”不符合协议“INStartAudioCallIntentHandling”
Type ‘IntentHandler’ does not conform to protocol ‘INStartAudioCallIntentHandling’
我使用的Xcode 8.2.1。我把func handle(startAudioCall intent: INStartAudioCallIntent, completion: (INStartAudioCallIntentResponse) -> Void)
方法放入课堂。为什么我得到这个错误。请帮帮我。
你应该还添加
func confirm(startAudioCall: INStartAudioCallIntent, completion: (INStartAudioCallIntentResponse) -> Void)
和
func resolveContacts(forStartAudioCall: INStartAudioCallIntent, with: ([INPersonResolutionResult]) -> Void)
使用INStart音频呼叫处理意向协议的方法来解决 ,确认和处理请求用 指定用户开始仅音频通话。在您的Intents 分机的对象中采用此协议,该分机能够验证呼叫信息。
夫特3.1溶液。
我们正在通过来自联系人显示名称的信息传递该用户活动。我需要说明我要打电话给谁。
我有这个简单的数组,这是一个模拟数据库的表示。也许在你的应用程序中有某种具有他们所有联系信息的用户列表,并且你可以根据传入resolveContacts的信息来检查这些联系人。用户说他们想给戴夫打电话,我确定那是在数据库中,如果是,那么我打电话给戴夫。而为了打电话,你需要一个INPerson,它需要一个personHandle,它基本上是一个人的唯一标识符。
您可以使用电子邮件或电话号码。我选择在这里用电话号码。如果它有合适的名称,它会创建这个INPersonHandle,将它作为一个人传递给这个电话号码和任何名字,如果它与我现有的联系人匹配,然后我说那个人的完成是成功的。如果没有匹配的联系人,那么我们会回顾用户说我们需要一个值。
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()])
}
}
他们都是可选的,没有帮助。 – EternalLight
@EternalLight检查了这个? https://forums.developer.apple.com/thread/62250 – JuicyFruit
是的,正在阅读。他们说这个问题是在Swift 3中使用了@escaping属性。在Swift 2.3中,默认情况下会关闭Closures,它应该可以正常工作,但它不会。 – EternalLight