Last active
January 7, 2019 21:52
-
-
Save uknowmeright/1891141f77580d9cf834cdd5ecfaa8a0 to your computer and use it in GitHub Desktop.
rate my app popup #tags: swift, rating, ios
This file contains hidden or 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
// | |
// PaulsRatingManager.swift | |
// | |
// Created by Paul on 1/7/19. | |
// Copyright © 2019 Paul Lehn. All rights reserved. | |
// | |
import Foundation | |
import StoreKit | |
class PaulsRatingManager { | |
private static let instance = PaulsRatingManager() | |
var sharedInstance: PaulsRatingManager{ | |
return .instance | |
} | |
// called from appdelegate didfinishLaunchingWithOptions: | |
static func incrementAppOpenedCount() { | |
let userdefault = UserDefaults.standard | |
let savedvalue = userdefault.integer(forKey: "AppOpenedCount") | |
if savedvalue == 0 { | |
print("Not saved ") | |
userdefault.set(1, forKey: "AppOpenedCount") | |
} | |
else{ | |
userdefault.set(savedvalue+1, forKey: "AppOpenedCount") | |
} | |
} | |
static func checkAppOpenCountAndAskReview(){ | |
let userdefault = UserDefaults.standard | |
let appopencountvalue = userdefault.integer(forKey: "AppOpenedCount") | |
if appopencountvalue % 10 == 0 { | |
print("its been 10 times so ask for review ") | |
PaulsRatingManager().requestReview() | |
} | |
else{ | |
print("not enough open counts dont show ") | |
} | |
} | |
fileprivate func requestReview() { | |
if #available(iOS 10.3, *) { | |
SKStoreReviewController.requestReview() | |
} else { | |
// Fallback on earlier versions | |
// Try any other 3rd party or manual method here. | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment