Created
April 14, 2017 05:23
-
-
Save evgenmikhaylov/eeeb56ddcd73a698a74d93e249e3c9f9 to your computer and use it in GitHub Desktop.
iOS application launch counter written on Obj-C
This file contains 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
#import <UIKit/UIKit.h> | |
@interface AppLaunchCounter : NSObject | |
+ (BOOL)isFirstLaunch; | |
+ (NSUInteger)numberOfLaunches; | |
@end |
This file contains 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
#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