如何从Received Message获取MSMessage摘要文本?

时间:2016-09-30 07:19:17

标签: ios swift3 imessage ios-extensions imessage-extension

我在MSMessage中传递摘要消息,但是当在另一端收到消息时尝试获取时,它返回nil。

以下是创建消息的代码

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返回nil。

override func didReceive(_ message: MSMessage, conversation: MSConversation) {

     print("DID RECEIVE MESSAGE: \(message.summaryText)")        
}

当用户点击消息时,也会返回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)
        }

    }

}

任何人都有想法,为什么会发生这种情况或者出现任何问题?

1 个答案:

答案 0 :(得分:2)

愿这会有所帮助

def __ne__(self, value):
    temp1 = self.v[:]
    temp2 = self.n[:]
    temp3 = value.v[:]
    temp4 = value.n[:]
    temp1.sort()
    temp2.sort()
    temp3.sort()
    temp4.sort()
    result = True if not (temp1 != temp3 and temp2 != temp4) else False
    return result

参考&帮助来源:Transitioning to IPv6-only networks

另请参阅:https://www.hackingwithswift.com/ios10