2017-08-15 95 views
1

我一直在SiriKit一段時間,我的演示結果並沒有得到我的老闆滿意。 通過閱讀所有Apple文檔&盡我所能在線搜索,我仍然無法找到一種方法來跳過SendMessageIntent中的確認步驟!SiriKit INSendMessageIntent跳過確認代理


這是我的目的:

解決用戶意見的Siri後,

func resolveContent(forSendMessage intent: INSendMessageIntent, with completion: @escaping (INStringResolutionResult) -> Void) { 
    if let text = intent.content, !text.isEmpty { 
     if text == "Login with Touch ID" { 
      completion(INStringResolutionResult.success(with: text)) 
     } else if text == "Change password"{ 
      completion(INStringResolutionResult.success(with: text)) 
     } 
     completion(INStringResolutionResult.disambiguation(with: ["Login with Touch ID", "Change password"])) 
    } else { 
     completion(INStringResolutionResult.disambiguation(with: ["Login with Touch ID", "Change password"])) 
    } 
} 

跳過此步驟 「確認」,

func confirm(sendMessage intent: INSendMessageIntent, completion: @escaping (INSendMessageIntentResponse) -> Void) { 
    // Verify user is authenticated and your app is ready to send a message. 

    let userActivity = NSUserActivity(activityType: NSStringFromClass(INSendMessageIntent.self)) 
    let response = INSendMessageIntentResponse(code: .success, userActivity: userActivity) 

    completion(response) 
} 

,直接做手柄委託,

func handle(sendMessage intent: INSendMessageIntent, completion: @escaping (INSendMessageIntentResponse) -> Void) { 
    // Implement your application logic to send a message here. 

    let userActivity = NSUserActivity(activityType: NSStringFromClass(INSendMessageIntent.self)) 
    let response = INSendMessageIntentResponse(code: .success, userActivity: userActivity) 

    completion(response) 
} 

希望有人能爲我解答這個問題。非常感謝!

回答

0

confirm功能是可選的,你不需要實現它以符合INSendMessageIntentHandling協議,只需要handle(intent:completion:)。這表明您可以跳過確認部分。

您應該刪除confirm函數,並且SiriKit會直接調用您的handle函數,而不進行確認。

+0

大衛你好,謝謝你的提問。 我試過你的方法來完成我的目標,但是在刪除確認功能後,我的Siri仍然確認我發送的消息。除了刪除確認功能外,有沒有我錯過的部分? –