3
我試圖解碼有另一個URL(單獨編碼)作爲查詢參數中的URL網址解碼:問題與iOS版
com.testScheme://openurl?url=https%3A%2F%2Fm%2Euber%2Ecom%2Ful%3Faction%3DsetPickup%26pickup%3Dmy%5Flocation%26dropoff%5Bformatted%5Faddress%5D%3D5394%2520General%2520Hood%2520Trl%2C%2520Nashville%2520TN
但是,下面的代碼似乎是「雙解碼」的兩次編碼的網址。
guard let urlComponents = URLComponents(url: url, resolvingAgainstBaseURL: false),
let requestType = urlComponents.host else {
return false
}
if requestType.lowercased() == "openurl" {
guard let queryItems = urlComponents.queryItems,
let urlString = queryItems.filter({ $0.name == "url" }).first?.value?.removingPercentEncoding,
let url = URL(string: urlString) else {
//unable to get parameters
return false
}
DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + DispatchTimeInterval.milliseconds(25)) {
UIApplication.shared.openURL(url)
}
return true
}
的urlString
輸出:
https://m.uber.com/ul?action=setPickup&pickup=my_location&dropoff[formatted_address]=5394 General Hood Trl, Nashville TN
我需要urlString
是:
https://m.uber.com/ul?action=setPickup&pickup=my_location&dropoff[formatted_address]=5394%20General%20Hood%20Trl,%20Nashville%20TN
爲什麼出現 「雙解碼」,我會如何解決這個問題?
唉唉去除
removingPercentEncoding
...這樣的查詢項目已經解碼了我。我懂了。感謝您的及時回覆。當我讓我在另一個5分鐘時,我會將它標記爲答案。 – Jake