Skip to content

Instantly share code, notes, and snippets.

@philippeauriach
Last active June 14, 2020 17:01
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 philippeauriach/311feff934205cff2f767b5e47653862 to your computer and use it in GitHub Desktop.
Save philippeauriach/311feff934205cff2f767b5e47653862 to your computer and use it in GitHub Desktop.
A simple helper to trigger apple Storekit review only for users who actually uses the app
// when the user actullay uses your app (eg create something, or consults something important)
StoreReviewHelper.incrementEventCount()
// when the use may have the time to review the app (will not always show the review prompt, only if the event count is matched and Apple decides to show it)
StoreReviewHelper.checkAndAskForReview()
import Foundation
import StoreKit
struct StoreReviewHelper {
fileprivate static let STORE_REVIEW_EVENT_COUNT = "STORE_REVIEW_EVENT_COUNT"
static func incrementEventCount() { // called from appdelegate didfinishLaunchingWithOptions:
let eventCount = UserDefaults.standard.integer(forKey: STORE_REVIEW_EVENT_COUNT) + 1
UserDefaults.standard.set(eventCount, forKey: STORE_REVIEW_EVENT_COUNT)
}
static func checkAndAskForReview() {
if USER_IS_LOGGED_IN == false {
return
}
let eventCount = UserDefaults.standard.integer(forKey: STORE_REVIEW_EVENT_COUNT)
switch eventCount {
case 10, 15:
StoreReviewHelper().requestReview()
case _ where eventCount % 20 == 0 :
StoreReviewHelper().requestReview()
default:
log.debug("Event count is : \(eventCount)")
break;
}
}
fileprivate func requestReview() {
if #available(iOS 10.3, *) {
// this will not be shown everytime. Apple has some internal logic on how to show this.
SKStoreReviewController.requestReview()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment