Shark Deng

Interactive Designer @Shanju Design in Shanghai

touched caffe / mxnet / python / wordpress / bootstrap / Arduino / Raspberry Pi / webgl / three.js / PIXI / 3dMax

Email

Github

Swift – app评分

2019-11-20 17:36:50

import Foundation
import StoreKit

class Rate{

    static let runCountKey = "numberOfRuns"
    static let minimumRunCount = 5
    
    
    //find suitable time to use this func
    class func popRateAlert(){
        let runs = getSavedRunCounts()
        if runs > minimumRunCount {
            if #available(iOS 10, *){
                SKStoreReviewController.requestReview() //core
            }
        } else {
            print("run count requirement is not satisfied")
        }
        
    }
    
    //This func is used in AppDelegate / applicationDidFinishLaunching
    class func addAppRuns(){
        //let usD = UserDefaults()
        let runs = getSavedRunCounts() + 1
        UserDefaults.standard.setValuesForKeys([runCountKey: runs]) //用单例,避免存取不一致
        UserDefaults.standard.synchronize()
    }
    
    class func getSavedRunCounts() -> Int{
        //let usD = UserDefaults()
        let savedRuns = UserDefaults.standard.value(forKey: runCountKey)
        
        var runs = 0
        if savedRuns != nil {
            runs = savedRuns as! Int
        }
        print("has run \(runs)")
        return runs
    }
}

 



——By SharkDeng
如果你喜欢我的文章,欢迎红包赞赏

Leave a Reply

Your email address will not be published. Required fields are marked *