How to request users to review your app in SwiftUI

⋅ 2 min read ⋅ SwiftUI

Table of Contents

How to request users to review your app in SwiftUI

In iOS 16, SwiftUI has a native way to ask for users' feedback and ratings.

To present a native prompt asking for the App Store rating and review, you need to do two things.

  1. Import the StoreKit framework.
  2. Call RequestReviewAction when you want to request users to review your app.
import SwiftUI
import StoreKit

struct ContentView: View {
// 1
@Environment(\.requestReview) var requestReview

var body: some View {
Text("Hello, world!")
.padding()
.onAppear {
// 2
requestReview()
}
}
}

1 RequestReviewAction is an action that will present a prompt to ask a user to rate our app. We can get the action from an environment value, \.requestReview, which is declared in the StoreKit framework.
2 After we get access to this action, just call it when you want to ask for the user's rating.

This is what the UI looks like.

Request review popup dialog.
Request review popup dialog.

You can easily support sarunw.com by checking out this sponsor.

Sponsor sarunw.com and reach thousands of iOS developers.

Limitations

Apple is quite serious when it comes to user experiences, and they want to control how often we can ask for a user's review.

So, even if you explicitly call requestReview(), the review popup might not show up.

Here are the criteria Apple uses to decide whether to show it or not.

  1. If the person hasn't rated or reviewed your app on this device, StoreKit displays the ratings and review request a maximum of three times within a 365-day period.

  2. If the person has rated or reviewed your app on this device, StoreKit displays the ratings and review request if the app version is newand if more than 365 days have passed since the person’s previous review.

  3. Even if all criteria are met, there is a chance that the prompt will not display due to Apple's hidden criteria, e.g., frequency. So, don't call the method in response to a button tap or other user actions.

You can easily support sarunw.com by checking out this sponsor.

Sponsor sarunw.com and reach thousands of iOS developers.

When should I request a rating

Since the number of times you can request a review is limited, you should call it when it matters.

You probably want to ask for a review when users will likely get one.

There are no rules for this, but I can give some examples.

  1. When users repeatedly come back to your app. This shows users are happy with your app and find it helpful.
  2. After significant events, e.g., completed a game level or finished some tasks.

In summary, you should ask for a review when users feel positive about your apps.

So, your code might look like this.

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

var body: some View {
Text("Hello, world!")
.padding()
.onAppear {
requestReviewIfAppropriated()
}
}
@MainActor
private func requestReviewIfAppropriated() {
let numberOfVisits = 10
let numberOfSignificantEvents = 10
if numberOfVisits > 5 || numberOfSignificantEvents > 5 {
requestReview()
}
}
}

In reality, numberOfVisits and numberOfSignificantEvents should come from your database, i.e., UserDefaults.


Read more article about SwiftUI or see all available topic

Enjoy the read?

If you enjoy this article, you can subscribe to the weekly newsletter.
Every Friday, you'll get a quick recap of all articles and tips posted on this site. No strings attached. Unsubscribe anytime.

Feel free to follow me on Twitter and ask your questions related to this post. Thanks for reading and see you next time.

If you enjoy my writing, please check out my Patreon https://www.patreon.com/sarunw and become my supporter. Sharing the article is also greatly appreciated.

Become a patron Buy me a coffee Tweet Share
Previous
How to copy text to the clipboard in iOS

Learn how to copy and paste text from clipboard in iOS.

Next
How to create custom view modifiers in SwiftUI

Learn how to create reuse styles using ViewModifier.

← Home