今天爱分享给大家带来iOS 开发 判断应用程序是否为 第一次/首次 打开【附代码】,希望能够帮助到大家。
第一步:在AppDelegate中当应用启动完成后加入一下代码:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
//NSUserDefaults非常好用,并不需要用户在程序中设置NSUserDefaults的全局变量,需要在哪里使用NSUserDefaults的数据,那么就在哪里创建一个NSUserDefaults对象,然后进行读或者写澡作。
if (![[NSUserDefaults standardUserDefaults]boolForKey:@"everLaunched"]) {
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"everLaunched"];
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"firstLaunch"];
}else{
[[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"firstLaunch"];
}
// Override point for customization after application launch.
return YES;
}
第二步:在ViewController的.m的ViewDidLoad方法中添加如下代码:
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
if ([[NSUserDefaults standardUserDefaults] boolForKey:@"firstLaunch"]) {
// 这里判断是否第一次
UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"第一次"
message:@"进入App"
delegate:self
cancelButtonTitle:@"我知道了"
otherButtonTitles:nil];
[alert show];//使用UIAlertView显示应用是否为第一次启动
}
}
原文链接:http://blog.itblood.com/979.html,转载请注明出处。

![暗黑地牢 官方中文版+荡欲扩展MOD+大量MOD[新整合][电脑/9.5G] [地牢探索SLG/中文/动态]](/wp-content/uploads/replace/2025/10/06/c4e948ec5a512069ab26b9577b6a6a89.webp)