BLACK FRIDAY SALE: Save big on all my Swift books and bundles! >>

How to ask the user to review your app

Paul Hudson    @twostraws   

Updated for Xcode 14.1

New in iOS 16

If you import StoreKit into your SwiftUI app, you’ll gain access to an environment key called requestReview, which allows you to prompt the user to leave a review for your app.

To use it, first important StoreKit into your project, add the environment key as property in your view, then call it at an appropriate time. Here’s some code to get you started:

import StoreKit
import SwiftUI

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

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

Download this as an Xcode project

Important: Apple hasn’t documented this because, well, Apple, but I would imagine this works the same as the older UIKit equivalent where this is a request to show the review dialog – there’s a good chance it will do nothing, because the system doesn’t want to spam the user with messages.

So, even though I’ve just shown you a code example using a button, please be much smarter in your own projects: wait until the user has used your app successfully quite a few times so they are happy, then call requestReview() in a way that is not in response to a button press – remember, it might do nothing at all.

Hacking with Swift is sponsored by RevenueCat

SPONSORED In-app subscriptions are a pain to implement, hard to test, and full of edge cases. RevenueCat makes it straightforward and reliable so you can get back to building your app. Oh, and it's free if your app makes less than $10k/mo.

Learn more

Sponsor Hacking with Swift and reach the world's largest Swift community!

Similar solutions…

BUY OUR BOOKS
Buy Pro Swift Buy Pro SwiftUI Buy Swift Design Patterns Buy Testing Swift Buy Hacking with iOS Buy Swift Coding Challenges Buy Swift on Sundays Volume One Buy Server-Side Swift Buy Advanced iOS Volume One Buy Advanced iOS Volume Two Buy Advanced iOS Volume Three Buy Hacking with watchOS Buy Hacking with tvOS Buy Hacking with macOS Buy Dive Into SpriteKit Buy Swift in Sixty Seconds Buy Objective-C for Swift Developers Buy Beyond Code

Was this page useful? Let us know!

Average rating: 1.0/5

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.