There's a dictionary app (Logeion) that I want my app to open. When the user hightlights a word in my app, and presses the Dictionary toolbar button, the dictionary app should open with the dictionary entry for the highlighted word displayed.
This is exactly what happens so long as the highlighted word has only ascii characters. But when the word has unicode characters, the dictionary opens, but the entry for the word is not displayed.
I know that URLs will not accept unicode characters as-is, so I tried escaping them with this code:
let escapedString = selectedText.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? ""
let logeionURL = URL(string: "LogeionLookUp://" + escapedString)
if let url = logeionURL {
UIApplication.shared.open(url, options: [:], completionHandler: {success in print(url, "\n", success)})
}
The selectedText variable is a String that holds the text that the user has highlighted. (Yes, I've checked.) I've tried a few other values besides .urlPathAllowed in line #1, but without effect. I know that the url is valid, because the app does open and the completionHandler runs, even with unicode strings.
Is there some other way to get uincode characters into the URL? I know that the dictionary app will work with unicode characters, because I've seen another app do precisely what I want my app to do with them. Apart from "Ask the app developer how they did it", any advice would be appreciated!