检查iPhone应用程序是否第一次运行的最佳方法 [英] Best way to check if an iPhone app is running for the first time
本文介绍了检查iPhone应用程序是否第一次运行的最佳方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想检查我的iPhone应用程序是否第一次运行。我可以在documents文件夹中创建一个文件并检查该文件以查看这是否是第一次运行应用程序,但我想知道是否有更好的方法来执行此操作。
I want to check if my iPhone app is running for the first time. I can create a file in the documents folder and check that file to see if this is the first time the app is running, but I wanted to know if there is a better way to do this.
推荐答案
我喜欢使用NSUserDefaults来存储第一次运行的指示。
I like to use NSUserDefaults to store an indication of the the first run.
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
if (![defaults objectForKey:@"firstRun"])
[defaults setObject:[NSDate date] forKey:@"firstRun"];
[[NSUserDefaults standardUserDefaults] synchronize];
您可以稍后测试...
You can then test for it later...
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
if([defaults objectForKey:@"firstRun"])
{
// do something or not...
}
这篇关于检查iPhone应用程序是否第一次运行的最佳方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文