UIApplication.shared.open 仅适用于 https
UIApplication.shared.open only works with https
我试图用 UIApplication.shared.open 功能打开 url 但我有点困惑,因为它不适用于 www.google.com and its working for https://www.google.com。
struct GetIsoCode: View {
@State var titile = "www.google.com"
var body: some View {
Text(titile)
.onTapGesture {
let urlS = URL(string:titile)
if let url = urlS {
UIApplication.shared.open(url) { (response) in
print(response)
}
}
}
}
}
第一个用例:
输入url:
www.google.com
输出:
Failed to open URL www.google.com: Error Domain=NSOSStatusErrorDomain Code=-50 "invalid input parameters" UserInfo={NSDebugDescription=invalid input parameters, _LSLine=234, _LSFunction=-[_LSDOpenClient openURL:options:completionHandler:]}
第二个用例:
输入:
https://www.google.com
结果:工作正常。
有人可以向我解释如何从两个链接显示 google 吗,我已经尝试通过上面的方法实现,但还没有结果。
文档说:
UIKit supports many common schemes, including the http, https, tel,
facetime, and mailto schemes.
Use this method to open the specified resource. If the specified URL
scheme is handled by another app, iOS launches that app and passes the
URL to it. (Launching the app brings the other app to the foreground.)
If no app is capable of handling the specified scheme, the completion
handler is called with the success parameter set to NO.
To determine whether an app is installed that is capable of handling
the URL, call the canOpenURL: method before calling this one
- 字符串“www.google.com”是哪个URL方案?
- 先调用canOpenURL,再调用open(url:)
我试图用 UIApplication.shared.open 功能打开 url 但我有点困惑,因为它不适用于 www.google.com and its working for https://www.google.com。
struct GetIsoCode: View {
@State var titile = "www.google.com"
var body: some View {
Text(titile)
.onTapGesture {
let urlS = URL(string:titile)
if let url = urlS {
UIApplication.shared.open(url) { (response) in
print(response)
}
}
}
}
}
第一个用例:
输入url:
www.google.com
输出:
Failed to open URL www.google.com: Error Domain=NSOSStatusErrorDomain Code=-50 "invalid input parameters" UserInfo={NSDebugDescription=invalid input parameters, _LSLine=234, _LSFunction=-[_LSDOpenClient openURL:options:completionHandler:]}
第二个用例:
输入:
https://www.google.com
结果:工作正常。
有人可以向我解释如何从两个链接显示 google 吗,我已经尝试通过上面的方法实现,但还没有结果。
文档说:
UIKit supports many common schemes, including the http, https, tel, facetime, and mailto schemes.
Use this method to open the specified resource. If the specified URL scheme is handled by another app, iOS launches that app and passes the URL to it. (Launching the app brings the other app to the foreground.) If no app is capable of handling the specified scheme, the completion handler is called with the success parameter set to NO.
To determine whether an app is installed that is capable of handling the URL, call the canOpenURL: method before calling this one
- 字符串“www.google.com”是哪个URL方案?
- 先调用canOpenURL,再调用open(url:)