Reading time: 1 min

This recipe shows how to request app review in SwiftUI on any version. This is the SwiftUI equivalent of requestReview(in:) method and is supported natively on SwiftUI 4, but can also work on earlier versions.

The end result looks like this:

preview

SwiftUI 1-3 (iOS 13-15)

On any SwiftUI version, you can invoke SKStoreReviewController's requestReview(in:) method and provide it with the currently active UIWindowScene. You can get the current window scene in SwiftUI by following steps from this recipe. Here's the full code:

import StoreKit

struct RequestReviewTest: View {
  var body: some View {
    Button("Review our app!") {
      if let scene = UIApplication.shared.connectedScenes
        .first(where: { $0.activationState == .foregroundActive }) as? UIWindowScene {
          SKStoreReviewController.requestReview(in: scene)
        }
    }
  }
}

SwiftUI 4+ (iOS 16+)

SwiftUI 4 supports this functionality natively with requestReview. To use this, be sure to:

  1. Import StoreKit.
  2. Get the requestReview environment variable.
  3. Invoke requestReview when needed.
import StoreKit

struct RequestReviewTest: View {
  @Environment(\.requestReview) var requestReview

  var body: some View {
    Button("Review our app!") {
      requestReview()
    }
  }
}

Next Post Previous Post