如何从收到的消息中获取 MSMessage 摘要文本?
How to get MSMessage summary text from Received Message?
我在 MSMessage 中传递摘要消息,但是当尝试获取另一端收到的消息时,它 returns 无。
下面是创建消息的代码。
fileprivate func composeMessage(with url: String, andEventInfo eventInfo: NSDictionary?) -> MSMessage {
let message = MSMessage(session:MSSession())
message.url = URL(string: url)
message.layout = createTemplateForEvent(eventInfo: eventInfo!)
message.summaryText = "SAMPLE MESSAGE"
return message
}
在当前对话中发送消息
let message = composeMessage(with: url!,andEventInfo: eventInfo)
activeConversation?.insert(message, completionHandler: { (error) in
print(error)
})
现在,在接收端
此处summaryText
returns无。
override func didReceive(_ message: MSMessage, conversation: MSConversation) {
print("DID RECEIVE MESSAGE: \(message.summaryText)")
}
此外,当用户点击消息时,它也会 returns nil
override func willTransition(to presentationStyle: MSMessagesAppPresentationStyle) {
guard let conversation = activeConversation else { fatalError("Expected an active converstation") }
// Present the view controller appropriate for the conversation and presentation style.
if presentationStyle == .expanded {
if conversation.selectedMessage != nil {
print(conversation.selectedMessage?.summaryText)
presentViewController(for: conversation, with: presentationStyle)
}
}
}
任何人都知道为什么会发生这种情况或出现任何问题?
希望这会有所帮助
override func didReceive(_ message: MSMessage, conversation: MSConversation) {
// Called when a message arrives that was generated by another instance of this
// extension on a remote device.
// Use this method to trigger UI updates in response to the message.
guard let messageURL = message.url else { return }
guard let urlComponents = NSURLComponents(url: messageURL, resolvingAgainstBaseURL: false), let queryItems = urlComponents.queryItems else { return }
print("URL Components", urlComponents)
print("queryItems", queryItems)
for item in queryItems {
print("Received \(item.name) with value \(item.value)")
}
}
参考和帮助来源:https://www.hackingwithswift.com/ios10
另请参阅:iOS10 iMessage : Unable to insert data into iMessage using MSConversation
我在 MSMessage 中传递摘要消息,但是当尝试获取另一端收到的消息时,它 returns 无。
下面是创建消息的代码。
fileprivate func composeMessage(with url: String, andEventInfo eventInfo: NSDictionary?) -> MSMessage {
let message = MSMessage(session:MSSession())
message.url = URL(string: url)
message.layout = createTemplateForEvent(eventInfo: eventInfo!)
message.summaryText = "SAMPLE MESSAGE"
return message
}
在当前对话中发送消息
let message = composeMessage(with: url!,andEventInfo: eventInfo)
activeConversation?.insert(message, completionHandler: { (error) in
print(error)
})
现在,在接收端
此处summaryText
returns无。
override func didReceive(_ message: MSMessage, conversation: MSConversation) {
print("DID RECEIVE MESSAGE: \(message.summaryText)")
}
此外,当用户点击消息时,它也会 returns nil
override func willTransition(to presentationStyle: MSMessagesAppPresentationStyle) {
guard let conversation = activeConversation else { fatalError("Expected an active converstation") }
// Present the view controller appropriate for the conversation and presentation style.
if presentationStyle == .expanded {
if conversation.selectedMessage != nil {
print(conversation.selectedMessage?.summaryText)
presentViewController(for: conversation, with: presentationStyle)
}
}
}
任何人都知道为什么会发生这种情况或出现任何问题?
希望这会有所帮助
override func didReceive(_ message: MSMessage, conversation: MSConversation) {
// Called when a message arrives that was generated by another instance of this
// extension on a remote device.
// Use this method to trigger UI updates in response to the message.
guard let messageURL = message.url else { return }
guard let urlComponents = NSURLComponents(url: messageURL, resolvingAgainstBaseURL: false), let queryItems = urlComponents.queryItems else { return }
print("URL Components", urlComponents)
print("queryItems", queryItems)
for item in queryItems {
print("Received \(item.name) with value \(item.value)")
}
}
参考和帮助来源:https://www.hackingwithswift.com/ios10
另请参阅:iOS10 iMessage : Unable to insert data into iMessage using MSConversation