Skip to content

Instantly share code, notes, and snippets.

@meyusufdemirci
Last active March 24, 2018 18:58
Show Gist options
  • Save meyusufdemirci/f4b8c28886c9f2c9441ea0ca647e44d8 to your computer and use it in GitHub Desktop.
Save meyusufdemirci/f4b8c28886c9f2c9441ea0ca647e44d8 to your computer and use it in GitHub Desktop.
import UIKit
import StoreKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// if there is an object which is called appLaunchCount
// means it is not the first launch
if ((UserDefaults.standard.object(forKey: "appLaunchCount")) != nil) {
var appLaunchCount = UserDefaults.standard.object(forKey: "appLaunchCount") as? Int
appLaunchCount = appLaunchCount! + 1
// saves appLaunchCount to local
UserDefaults.standard.set(appLaunchCount!, forKey: "appLaunchCount")
UserDefaults.standard.synchronize()
if appLaunchCount == 2 {
// works after 20 seconds of the app launch
DispatchQueue.main.asyncAfter(deadline: .now() + 20, execute: {
// shows review pop up
SKStoreReviewController.requestReview()
})
}
}
// if the app opens at the first time
else {
UserDefaults.standard.set(1, forKey: "appLaunchCount")
UserDefaults.standard.synchronize()
}
return true
}
func applicationWillResignActive(_ application: UIApplication) {}
func applicationDidEnterBackground(_ application: UIApplication) {}
func applicationWillEnterForeground(_ application: UIApplication) {}
func applicationDidBecomeActive(_ application: UIApplication) {}
func applicationWillTerminate(_ application: UIApplication) {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment