Show uialertview after opening an app after 3 times?

↘锁芯ラ 提交于 2019-12-11 14:19:30

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!