因此,我正在搞乱iMessages
框架,并且为了向其他用户发送数据,必须将数据作为URLComponents
URL
发送。但我不知道如何发送一个字典作为messages.url
值使用。如何通过在Swift中使用字典来构建URL
func createMessage(data: dictionary) {
/*
The Dictionary has 3 values, 1 string and two arrays.
let dictionary = ["title" : "Title Of Dictionary", "Array1" : [String](), "Array2" : [String]() ] as [String : Any]
*/
let components = URLComponents()
let layout = MSMessageTemplateLayout()
layout.image = UIImage(named: "messages-layout.png")!
layout.imageTitle = "\(dictionary["title"])"
let message = MSMessage()
message.url = components.url!
message.layout = layout
self.activeConversation?.insert(message, completionHandler: { (error: Error?) in
print("Insert Message")
})
}
有谁知道我可以在URLComponents
送字典值URLQueryItems
保存为message.url
? PS:我想知道是否有可能为存储字典的URL创建扩展名,这是我尝试atm失败的原因。
斯威夫特4更新: 'FUNC queryItems(词典:[字符串:String]) - > [URLQueryItem] { return dictionary.map { URLQueryItem(name:$ 0.0,value:$ 0.1) } }' – palme
@palme thanks。我已经用你的代码片段更新了代码。 –