问题
Is it possible to show a Alertview when opening an app after lets say 3 times? Can this be done with NSUserDefaults?
Thanks!
回答1:
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"];
回答2:
if([[NSUserDefaults standardUserDefaults]integerForKey:@"launchCount"]==0){
[[NSUserDefaults standardUserDefaults]setInteger:1 forKey:@"launchCount"];
}else{
[[NSUserDefaults standardUserDefaults]setInteger:[[NSUserDefaults standardUserDefaults]integerForKey:@"launchCount"]+1 forKey:@"launchCount"];
}
来源:https://stackoverflow.com/questions/26471780/show-uialertview-after-opening-an-app-after-3-times