Count number of times app has been launched using Swift?
I would like to count the number of times my iOS application has been launched using Swift.
I would then like to take the number and display it using
NSLog each time.
- Custom back button on navigation bar
- segue loading viewcontroller but not displaying it
- Double touch on UIButton
- New Command 2 Apple Push Notification Not sending multiple alerts
- I get OSSpinLockLock when calling startDeviceMotionUpdatesToQueue inside a controller
- Align button image to right edge of UIButton
2 Solutions Collect From Internet About “Count number of times app has been launched using Swift?”
Add this in
Swift 3 and Swift 4:
// get current number of times app has been launched let currentCount = UserDefaults.standard.integer(forKey: "launchCount") // increment received number by one UserDefaults.standard.set(currentCount+1, forKey:"launchCount") // save changes to disk UserDefaults.standard.synchronize()
// get current number of times app has been launched let currentCount = NSUserDefaults.standardUserDefaults().integerForKey("launchCount") // increment received number by one NSUserDefaults.standardUserDefaults().setInteger(currentCount+1, forKey:"launchCount") // save changes to disk NSUserDefaults.standardUserDefaults().synchronize()
You can store a int to NSUserDefaults.
Every time when you load the app, you can increase the number and save it again.
Add this logic in ApplicationDidFinishLaunching method.
Hope this helps.
- How to add UITableView in a UIAlertView in swift
- Error importing Google Analytics iOS SDK using Cocoa Pods
- iTunes12.7 cannot install ipa
- Weird iOS bug with UITableViewCell and userInteractionEnabled
- iOS background Location not sending http request
- best way to add license section to iOS settings bundle
- How does clipsToBounds work?
- Objective-c – How to serialize audio file into small packets that can be played?
- How to completely hide the status bar in iOS using Cordova?
- Is it possible to run iOS simulator on a Mac without Xcode installed?
- swift : Failed to communicate with Interface Builder
- Changing tab bar item image and text color iOS
- Cocoapods pod stable build setting
- Make Update to a live iPhone app
- Cannot use ifstream in Xcode