You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

能否在WKWebView中实现应用评分请求功能?

应用评分请求功能实现方案(Swift + Xcode13)

可行性说明

完全可行,iOS官方提供的StoreKit框架支持应用评分/评论请求,和你用WKWebView加载本地HTML的实现逻辑无冲突,直接在原生Swift代码中集成即可,不需要改动WebView相关代码。

具体调用方法

1. 导入StoreKit框架

在需要调用评分功能的Swift文件顶部添加:

import StoreKit

2. 触发时机建议

避免App刚启动就弹框,建议在用户完成正向操作后触发(比如累计使用3次、完成核心功能流程),提升用户接受度。

3. 两种实现方式

方式一:原生弹窗评分(推荐,iOS10.3+支持)

系统会在App内直接弹出评分弹窗,用户无需离开App即可完成打分,且系统会自动限制弹窗频率(每年最多3次),无需自己做逻辑控制:

if let scene = UIApplication.shared.connectedScenes.first as? UIWindowScene {
    SKStoreReviewController.requestReview(in: scene)
}

方式二:跳转App Store写评论

如果需要引导用户撰写完整评论,可跳转至App Store详情页:

func openAppStoreReview() {
    // 替换为你的App在App Store Connect的ID(一串数字)
    let appID = "123456789"
    guard let url = URL(string: "itms-apps://itunes.apple.com/app/id\(appID)?action=write-review") else { return }
    UIApplication.shared.open(url, options: [:], completionHandler: nil)
}

4. 从本地HTML触发评分(可选)

如果需要通过网页内的按钮触发评分,可通过JS与原生Swift交互实现:

  1. 配置WKWebView的消息处理器:
let contentController = WKUserContentController()
contentController.add(self, name: "callAppReview")

let config = WKWebViewConfiguration()
config.userContentController = contentController

let webView = WKWebView(frame: view.bounds, configuration: config)
  1. 实现WKScriptMessageHandler协议:
extension YourViewController: WKScriptMessageHandler {
    func userContentController(_ userContentController: WKUserContentController, didReceive message: WKScriptMessage) {
        if message.name == "callAppReview" {
            // 调用原生评分逻辑
            if let scene = UIApplication.shared.connectedScenes.first as? UIWindowScene {
                SKStoreReviewController.requestReview(in: scene)
            }
        }
    }
}
  1. 在本地HTML中添加触发按钮:
<button onclick="window.webkit.messageHandlers.callAppReview.postMessage(null)">给App评分</button>

内容的提问来源于stack exchange,提问作者Vitor Selva

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.19 15:35:29