3次打开应用后显示uialertview?

时间:2014-10-20 17:47:37

标签: ios objective-c uialertview

在3次打开应用后,是否可以显示Alertview?可以使用NSUserDefaults吗?

谢谢!

2 个答案:

答案 0 :(得分:4)

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"];

答案 1 :(得分:0)

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

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

    }