Swift version: 5.6
Many apps ask users to review their apps, but it’s increasingly common to see dark patterns such as apps pre-screening users so they get sent to the App Store only if they said they like the app.
To avoid this problem in the future, and also to provide a standardized interface that users can trust, iOS 10.3 brought a built-in way to ask users to review the app, and it couldn’t be much easier to use. In iOS 14 this was upgraded to rely on scenes, so it’s important your code makes the review request on an active scene.
But first, some important information:
Once you understand those rules, the process really couldn’t be easier. First, add this import
to your code:
import StoreKit
Then at some point in your app run this code:
if let scene = UIApplication.shared.connectedScenes.first(where: { $0.activationState == .foregroundActive }) as? UIWindowScene {
SKStoreReviewController.requestReview(in: scene)
}
That’s it!
Again, you should not call that in response to user input, although if you have any sense you won’t just put it inside viewDidAppear()
in your app.
Instead, consider storing a simple run count for your app using UserDefaults
, then calling the method after your app has been run 10 times. By that point it’s pretty clear the user keeps coming back to your app, so hopefully you have more chance of getting a positive review!
BUILD THE ULTIMATE PORTFOLIO APP Most Swift tutorials help you solve one specific problem, but in my Ultimate Portfolio App series I show you how to get all the best practices into a single app: architecture, testing, performance, accessibility, localization, project organization, and so much more, all while building a SwiftUI app that works on iOS, macOS and watchOS.
Sponsor Hacking with Swift and reach the world's largest Swift community!
Available from iOS 14.0
This is part of the Swift Knowledge Base, a free, searchable collection of solutions for common iOS questions.
Link copied to your pasteboard.