在 SwiftUI 中,你可以使用 UIApplication.shared.open(_:options:completionHandler:)
方法来跳转到 App Store。你需要提供一个包含你想要跳转到的 App Store 的 URL 的实例。
下面是一个示例代码:
import SwiftUI
struct ContentView: View {
var body: some View {
Button(action: {
// 跳转到 App Store
if let url = URL(string: "itms-apps://itunes.apple.com/app/idYOUR_APP_ID") {
UIApplication.shared.open(url, options: [:], completionHandler: nil)
}
}) {
Text("跳转到 App Store")
}
}
}
你需要将 YOUR_APP_ID
替换为你自己 App 的 ID。
请注意,为了在模拟器上测试这个功能,你需要在模拟器中打开 Safari,并在 Safari 中手动访问一下 App Store 的链接。这将设置正确的模拟器环境,以便正确跳转到 App Store。