使用SiriKit发送消息

时间:2017-09-17 18:01:42

标签: swift firebase sirikit

我已经有了一个消息传递应用程序,我想实现Siri发送消息。我已经添加了Intents扩展和所有内容,我只是在弄清楚如何发送消息时遇到了问题。我曾尝试使用相同的函数在ChatVC中发送消息,并将其复制并粘贴到IntentHandler.swift文件中,但它给了我一堆编译器错误。是否有某种类型的框架我应该用它来与应用程序进行通信来完成它?如果需要该信息,我将使用Firebase作为我的数据库。

更新代码:
请注意,此代码是我在用户发送正常消息时所具有的发送功能,这是我复制并粘贴到SiriIntent ...

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

    sendMessage()

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

func sendMessage(text: String?, date: Date, picture: UIImage?, location: String?, video: NSURL?, audio: String?) {

    var outgoingMessage: OutgoingMessage?

if let text = text {      

        let encryptedText = EncryptText(chatRoomID: chatRoomId, string: text)

        outgoingMessage = OutgoingMessage(message: encryptedText, senderId: FUser.currentUser()!.objectId, senderName: FUser.currentUser()!.firstname, date: date, status: kDELIVERED, type: kTEXT)
    }
  }

非常感谢您的帮助!

0 个答案:

没有答案