要在 Swift 中实现点击按钮跳转到当前 App 的线上 App Store 地址,可以使用 UIApplication 的 open 方法来打开一个 URL。

首先,你需要获取当前 App 的 App Store 链接。可以在 App Store Connect 中找到 App 的链接,或者使用以下代码获取当前 App 的 App Store 链接:

guard let appStoreUrl = URL(string: 'https://apps.apple.com/app/your-app-id') else {
    return
}

接下来,在点击按钮的动作方法中,使用 UIApplication 的 open 方法打开 URL:

@IBAction func goToAppStore(_ sender: UIButton) {
    guard let appStoreUrl = URL(string: 'https://apps.apple.com/app/your-app-id') else {
        return
    }
    
    UIApplication.shared.open(appStoreUrl)
}

确保将'your-app-id'替换为你的 App 的实际 App ID。

这样,当用户点击按钮时,就会打开当前 App 的线上 App Store 页面。

Swift 按钮跳转 App Store: 代码示例及步骤

原文地址: https://www.cveoy.top/t/topic/fTSW 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录