Last active
June 14, 2020 17:01
-
-
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
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
// 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() |
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
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