7

How to request users to review your app in SwiftUI

 9 months ago
source link: https://sarunw.com/posts/how-to-request-users-to-review-app-in-swiftui/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

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()
}
}
}

1RequestReviewAction 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.

AI Paraphrase:

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.

In a debug environment, the popup will always show to facilitate debugging.

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.

AI Paraphrase:

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.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK