简体   繁体   中英

How to get the count of number of times the app launch iPhone

Im developing a reminder app.

So my client want to set a rate this application popup message, that'll come up on the 10th time user open the app.is this possible.

How can i implement this?

Can anyone help me please.Thanks in advance

You could use NSUserDefaults for this:

    NSUserDefaults * userDefaults = [NSUserDefaults standardUserDefaults];
    NSInteger appLaunchAmounts = [userDefaults integerForKey:@"LaunchAmounts"];
    if (appLaunchAmounts == 10)
    {
        [self showMessage];
    }
    [userDefaults setInteger:appLaunchAmounts+1 forKey:@"LaunchAmounts"];

You can store that into the NSUserDefaults . Just update it in applicationDidFinishLaunching: .

You can save an integer in NSUserDefaults

- (void)setInteger:(NSInteger)value forKey:(NSString *)defaultName

Retrieve it and increment it every time the appDidFinishLaunching (or appWillEnterForeground) delegate methods is called. Probably best to use appWillEnterForeground as sometimes apps can lie in the background unterminated for days.

NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
NSInteger count = [defaults integerForKey:@"LaunchCount"];
count++;
/* Do checks and review prompt */
[defaults setInteger:count forKey:@"LaunchCount"];
[defaults synchronize];

This will store a value in NSUserDefaults called 'AppLaunchCount'.

- (BOOL)application:(UIApplication *)app didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {


if ([[NSUserDefaults standardUserDefaults] integerForKey:@"AppLaunchCount"])
{
    [[NSUserDefaults standardUserDefaults] setInteger:([[NSUserDefaults standardUserDefaults] integerForKey:@"AppLaunchCount"] + 1) forKey:@"AppLaunchCount"];
}
else
{
    [[NSUserDefaults standardUserDefaults] setInteger:1 forKey:@"AppLaunchCount"];
}
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM