在 SwiftUI中打開 a 非常容易URL,例如,正如我在這個答案中提到的那樣,但是,我有興趣使用默認搜索引擎在 Web 瀏覽器(例如 Safari)中打開以下字串:
樣本串
8883notaurl
是否可以選擇在默認搜索引擎中打開查詢,而不是像這樣撰寫 URL:
https://www.google.com/search?q=query
然后將其作為常規 URL 打開?
uj5u.com熱心網友回復:
您可以將x-web-search://方案與x-web-search://?[SearchValue].
示例代碼:
let urlStr = "x-web-search://?[SearchValue]"
if let url = URL(string: urlStr) {
if UIApplication.shared.canOpenURL(url) {
UIApplication.shared.open(url, options: [:]) { didEnd in
print("Did End: \(didEnd)")
}
} else {
print("Can't open URL")
}
} else {
print("Isn't URL")
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/454892.html
上一篇:Laravel自定義永久鏈接
下一篇:如何格式化字串選擇?
