Last active
May 15, 2020 19:06
-
-
Save abhimuralidharan/fc717fb27d1d7388524e70a09860a786 to your computer and use it in GitHub Desktop.
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
// | |
// StoreReviewHelper.swift | |
// Template1 | |
// | |
// Created by Apple on 14/11/17. | |
// Copyright © 2017 Mobiotics. All rights reserved. | |
// | |
import Foundation | |
import StoreKit | |
struct StoreReviewHelper { | |
static func incrementAppOpenedCount() { // called from appdelegate didfinishLaunchingWithOptions: | |
guard var appOpenCount = Defaults.value(forKey: UserDefaultsKeys.APP_OPENED_COUNT) as? Int else { | |
Defaults.set(1, forKey: UserDefaultsKeys.APP_OPENED_COUNT) | |
return | |
} | |
appOpenCount += 1 | |
Defaults.set(appOpenCount, forKey: UserDefaultsKeys.APP_OPENED_COUNT) | |
} | |
static func checkAndAskForReview() { // call this whenever appropriate | |
// this will not be shown everytime. Apple has some internal logic on how to show this. | |
guard var appOpenCount = Defaults.value(forKey: UserDefaultsKeys.APP_OPENED_COUNT) as? Int else { | |
Defaults.set(1, forKey: UserDefaultsKeys.APP_OPENED_COUNT) | |
return | |
} | |
switch appOpenCount { | |
case 10,50: | |
StoreReviewHelper().requestReview() | |
case _ where appOpenCount%100 == 0 : | |
StoreReviewHelper().requestReview() | |
default: | |
print("App run count is : \(appOpenCount)") | |
break; | |
} | |
} | |
fileprivate func requestReview() { | |
if #available(iOS 10.3, *) { | |
SKStoreReviewController.requestReview() | |
} else { | |
// Fallback on earlier versions | |
// Try any other 3rd party or manual method here. | |
} | |
} | |
} |
Is there a license for this file? Thanks!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I found from another page, that it's just a struct.
import Foundation