1
我遇到了一個我正在嘗試創建的消息擴展應用程序的問題。每當我嘗試將文本插入到對話中時,都不會發生任何事情。這是我使用的是什麼:iMessage應用程序不會將消息插入活動對話
import UIKit
import Messages
class MessagesViewController: MSMessagesAppViewController {
override func viewDidLoad() {
super.viewDidLoad()
let sendButton = UIButton(type: UIButtonType.custom)
sendButton.frame = CGRect(x: view.frame.midX, y: view.frame.midY, width: 100, height: 50)
sendButton.setTitle("Send", for: UIControlState.normal)
sendButton.addTarget(self, action: #selector(sendButtonTapped(sender:)), for: UIControlEvents.touchUpInside)
self.view.addSubview(sendButton)
}
func sendButtonTapped(sender: UIButton!){
let layout = MSMessageTemplateLayout()
layout.caption = "My Survey"
layout.image = UIImage(named: "myImage")
let message = MSMessage()
message.layout = layout
self.activeConversation?.insert(message, completionHandler: nil)
}
}
每當我使用此代碼什麼也沒有發生運行它。奇怪的部分是,如果我將self.activeConversation?
更改爲self.activeConversation!
,應用程序崩潰。我不明白爲什麼會發生這種情況,因爲我正在進行對話並且我的應用已加載。
這可能是因爲崩潰是activeConversarion零,你試圖解開它。 – mat
@mat但爲什麼它是零?該應用程序已加載,我正在iMessage中進行對話。 –
什麼是activeConversation?您發佈的代碼不足以確定崩潰來自何處。控制檯中有任何錯誤? – mat