Skip to content

Instantly share code, notes, and snippets.

@BradBroulik
Created March 17, 2018 16:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BradBroulik/4f7ec2750c2507c92f3e4ede1e24fcd1 to your computer and use it in GitHub Desktop.
Save BradBroulik/4f7ec2750c2507c92f3e4ede1e24fcd1 to your computer and use it in GitHub Desktop.
app-review-limit-by-usage
class AppReview : NSObject {
static let minimumAppLaunchCountForAppReview = 1
@objc static func requestReview() {
if (getAppLaunchCount() > minimumAppLaunchCountForAppReview) {
if #available(iOS 10.3, *) {
SKStoreReviewController.requestReview()
}
}
}
static func getAppLaunchCount() -> Int {
return UserDefaults.standard.integer(forKey: UserDefaults.Keys.appLaunchCount.rawValue)
}
// Set in application(_:didFinishLaunchingWithOptions:)
static func incrementAppLaunchCount() {
let incrementedAppLaunchCount = AppReview.getAppLaunchCount() + 1
UserDefaults.standard.set(incrementedAppLaunchCount, forKey: UserDefaults.Keys.appLaunchCount.rawValue)
UserDefaults.standard.synchronize()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment