Search code examples
iphoneobjective-cxcodelaunching-application

How should I count the number of launches of an application in iPhone


  • I have completed my application.
  • Now when user launches my application 5 times
  • I want to display an alert message that "You have used more than 5 times better to go for next version".

  • How should we count the number of launches and where do we call this alert view?


Solution

  • use NSUserDefaults in applicationDidBecomeActive:.

    NSUserDefaults * userDefaults = [NSUserDefaults standardUserDefaults];
            NSInteger appLaunchAmounts = [userDefaults integerForKey:@"LaunchAmounts"];
            if (appLaunchAmounts == 5)
            {
               //Use AlertView
    
    
            }
            [userDefaults setInteger:appLaunchAmounts+1 forKey:@"LaunchAmounts"];