Created
March 17, 2018 16:16
-
-
Save BradBroulik/4f7ec2750c2507c92f3e4ede1e24fcd1 to your computer and use it in GitHub Desktop.
app-review-limit-by-usage
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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