什么是 SolicitReviewLibrary?

SolicitReviewLibrary 是一个 Swift 包,用于管理评论请求流程。

对于您的应用程序的任何新版本,当达到操作阈值时,它会提示用户评价该应用程序。

目前,它仅适用于 iOS >= 14 和 macOS >= 11。

它支持多种语言。默认语言是英语。其他语言是简体中文、日语和德语。

使用方法

评论提示

  1. SolicitReviewLibrary (https://github.com/higracehuang/SolicitReviewLibrary.git) 添加到您的 iOS 或 macOS 应用程序项目的 Package Dependencies(软件包依赖项)中。

  2. 导入 SolicitReviewLibrary,并在 App 模块中调用 SolicitReviewLibrary.appInit()

例如,在 ExampleApp

import SwiftUI
import SolicitReviewLibrary

@main
struct ExampleApp: App {
  init() {
    SolicitReviewLibrary.appInit() // 0) Init for the app
  }
  var body: some Scene {
    WindowGroup {
      ContentView()
    }
  }
}
  1. 在您想要请求评论的 UI 中调用 requestReview

例如,在用户点击按钮 10 次后,它会提示请求评论。

import SwiftUI
import SolicitReviewLibrary

struct ContentView: View {
  @State private var buttonTapped = false
  
  let solicitReviewLibrary = SolicitReviewLibrary(checkpointCount: 10) // 1) Init
  
  var body: some View {
    VStack {
      Text("Button is \(buttonTapped ? "Tapped" : "Not Tapped")")
        .padding()
      
      Button(action: {
        self.buttonTapped.toggle()
        solicitReviewLibrary.requestReview() // 2) Prompt for review
      }) {
        Text("Tap Me!")
          .padding()
          .background(Color.blue)
          .foregroundColor(.white)
          .cornerRadius(8)
      }
    }
  }
}
  1. 构建应用程序并进行测试。

链接到 App Store 上的评论

idxxxxxxxxxxxx 替换为您的应用程序 ID。

import SwiftUI
import SolicitReviewLibrary

struct ContentView: View {
    var body: some View {
        if let reviewURL = SolicitReviewLibrary.getReviewURL(appStoreId: "idxxxxxxxxxxxx") {
            Link(destination: reviewURL) {
                Text("Rate This App 🙏")
            }
        }
    }
}

它将定向到 https://apps.apple.com/in/app/app-name/idxxxxxxxxxxxx?action=write-review

调试

在 Xcode 控制台中,查找带有标签 [SolicitReviewLibrary] 的调试信息以进行测试。

[SolicitReviewLibrary] Reset engagementCounter to 0
[SolicitReviewLibrary] Reset appVersionForStorage to 1.0.2
[SolicitReviewLibrary] count:1 currentVersion:1.0.2 lastVersionPromptedForReview:1.0.3
[SolicitReviewLibrary] count:2 currentVersion:1.0.2 lastVersionPromptedForReview:1.0.3