开发者

How to track how many times an iPhone app is opened?

I am building an iphone app and would like to keep track of how many times it has been opened so that I can prompt the user to do certain actions after it has been opened X number开发者_运维知识库 of times. I have thought about storing a variable in Core Data which I update every time it is opened, but this seems like a waste since it is a singleton data, not multiple instances of an object. What is the best way to store data like this and access it without slowing down the app opening time?


You can store it user defaults. Here is the code:

-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    [self countOpen];
}

-(void) countOpen {
    int _coutn= 0;
    _count=  [[[NSUserDefaults standardUserDefaults] objectForKey:@"AppCount"] intValue];

    [[NSUserDefaults standardUserDefaults] setObject:[NSString stringFormat:@"%d",_count+1] forKey:@"AppCount"];
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜