Skip to content

Instantly share code, notes, and snippets.

@evgenmikhaylov
Created April 14, 2017 05:23
Show Gist options
  • Save evgenmikhaylov/eeeb56ddcd73a698a74d93e249e3c9f9 to your computer and use it in GitHub Desktop.
Save evgenmikhaylov/eeeb56ddcd73a698a74d93e249e3c9f9 to your computer and use it in GitHub Desktop.
iOS application launch counter written on Obj-C
#import <UIKit/UIKit.h>
@interface AppLaunchCounter : NSObject
+ (BOOL)isFirstLaunch;
+ (NSUInteger)numberOfLaunches;
@end
#import "AppLaunchCounter.h"
NSString * const AppLaunchCounterNumberOfLaunchesKey = @"AppLaunchCounterNumberOfLaunchesKey";
@implementation AppLaunchCounter
+ (void)load {
NSUInteger numberOfLaunches = [[NSUserDefaults standardUserDefaults] integerForKey:AppLaunchCounterNumberOfLaunchesKey];
[[NSUserDefaults standardUserDefaults] setInteger:++numberOfLaunches forKey:AppLaunchCounterNumberOfLaunchesKey];
[[NSUserDefaults standardUserDefaults] synchronize];
}
+ (BOOL)isFirstLaunch {
return ([self numberOfLaunches] == 1);
}
+ (NSUInteger)numberOfLaunches {
return [[NSUserDefaults standardUserDefaults] integerForKey:AppLaunchCounterNumberOfLaunchesKey];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment