好的,我正在使用 iMessage 应用程序并尝试从此处选择的消息中解析 1 个以上的 url 查询项 - 我已成功在查询中仅获取/发送 1 个值:
override func willBecomeActive(with conversation: MSConversation) {
// Called when the extension is about to move from the inactive to active state.
// This will happen when the extension is about to present UI.
if(conversation.selectedMessage?.url != nil) //trying to catch error
{
let components = URLComponents(string: (conversation.selectedMessage?.url?.query?.description)!)
//let val = conversation.selectedMessage?.url?.query?.description
if let queryItems = components?.queryItems {
// process the query items here...
let param1 = queryItems.filter({$0.name == "theirScore"}).first
print("***************=> GOT IT ",param1?.value)
}
}
当我只有 1 个值时,只需打印conversation.selectedMessage?.url?.query?.description
我就可以得到一个带有 1 个值的可选值,这很好。但是有多个我无法找到一种干净的方法来按键获取特定值。
URLQueryItem
为 iMessage 解析给定键的正确方法是什么?