Jan
Jan

Reputation: 663

Show uialertview after opening an app after 3 times?

Is it possible to show a Alertview when opening an app after lets say 3 times? Can this be done with NSUserDefaults?

Thanks!

Upvotes: 0

Views: 131

Answers (2)

Ian MacDonald
Ian MacDonald

Reputation: 14030

int launches = [[NSUserDefaults standardUserDefaults] integerForKey:@"launchCount"];
if (launches > 3) {
  UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"My Alert" 
                                                  message:@"Some message" delegate:nil
                                        cancelButtonTitle:@"OK" otherButtonTitles:nil];
  [alert show];
}
[[NSUserDefaults standardUserDefaults] setInteger:launches+1 forKey:@"launchCount"];

Upvotes: 4

user2096064
user2096064

Reputation: 118

if([[NSUserDefaults standardUserDefaults]integerForKey:@"launchCount"]==0){
        [[NSUserDefaults standardUserDefaults]setInteger:1 forKey:@"launchCount"];

    }else{
        [[NSUserDefaults standardUserDefaults]setInteger:[[NSUserDefaults standardUserDefaults]integerForKey:@"launchCount"]+1 forKey:@"launchCount"];

    }

Upvotes: 0

Related Questions