A
A
artursk2016-01-07 17:26:59
iOS
artursk, 2016-01-07 17:26:59

How to keep an application open counter inside the application?

How to keep a counter of the number of application openings inside the application, to further implement the user's progress based on the number of entrances to the application?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Tikhonov, 2016-01-07
@artursk

NSUserDefaults to help
Update:

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
        
        ...
        let userDefaults = NSUserDefaults.standardUserDefaults()
        if var numberOfLaunches = userDefaults.objectForKey("numberOfLaunches") as? Int {
            numberOfLaunches++
            userDefaults.setInteger(numberOfLaunches, forKey: "numberOfLaunches")
        } else {
            let n = 1
            userDefaults.setInteger(n, forKey: "numberOfLaunches")
        }
        print(userDefaults.objectForKey("numberOfLaunches") as! Int)
        
        return true
    }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question