2017-04-01 163 views
3

我使用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)方法放入課堂。爲什麼我得到這個錯誤。請幫幫我。

回答

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

+0

他們都是可選的,沒有幫助。 – EternalLight

+0

@EternalLight檢查了這個? https://forums.developer.apple.com/thread/62250 – JuicyFruit

+0

是的,正在閱讀。他們說這個問題是在Swift 3中使用了@escaping屬性。在Swift 2.3中,默認情況下會關閉Closures,它應該可以正常工作,但它不會。 – EternalLight

0

夫特3.1溶液。

我們正在通過來自聯繫人顯示名稱的信息傳遞該用戶活動。我需要說明我要打電話給誰。

我有這個簡單的數組,這是一個模擬數據庫的表示。也許在你的應用程序中有某種具有他們所有聯繫信息的用戶列表,並且你可以根據傳入resolveContacts的信息來檢查這些聯繫人。用戶說他們想給戴夫打電話,我確定那是在數據庫中,如果是,那麼我打電話給戴夫。而爲了打電話,你需要一個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()]) 
    } 

} 
相關問題