08.openURL
前言
在 UIKit
中我们通常使用下面方式来打开 外部链接
,那么在 SwiftUI
中我们该怎样使用呢?
UIApplication.shared.open(url, options: [ : ], completionHandler: nil)
一、 注入环境变量
@Environment(\.openURL) var openURL
...
ZStack {
Color.blue
Text("App Store")
.fontWeight(.medium)
.foregroundColor(.white)
.onTapGesture {
openURL.callAsFunction(url) { accepted in }
}
}
...
二、 Link
Link(destination: url, label: {
ZStack {
Color.blue
Text("App Store")
.fontWeight(.medium)
.foregroundColor(.white)
}
})
参考
Last updated
Was this helpful?