【发布时间】:2021-10-29 19:00:55
【问题描述】:
我有一个 SwiftUI 应用程序。我有一个应该打开 youtube.com 的按钮设置,但我收到一条错误消息:
Failed to open URL www.youtube.com: Error Domain=NSOSStatusErrorDomain Code=-50 "invalid input parameters" UserInfo={NSDebugDescription=invalid input parameters, _LSLine=230, _LSFunction=-[_LSDOpenClient openURL:options:completionHandler:]}
这是我的代码:
import SwiftUI
struct HomeView: View {
var body: some View {
Button(action: {
if let yourURL = URL(string: "www.youtube.com") {
UIApplication.shared.open(yourURL, options: [:], completionHandler: nil)
}
}, label: {
Text("Open URL")
.frame(width: 200, height: 50)
.foregroundColor(.white)
.background(Color.blue)
.cornerRadius(16)
})
}
}
我也尝试过使用 Link 修饰符,但是没有用。
有人有解决办法吗?
【问题讨论】: