检测应用程序的第一次运行 [英] Detecting the first ever run of an app
本文介绍了检测应用程序的第一次运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在创建一个应用程序,当应用程序第一次启动时,我必须创建一个plist。我稍后将使用plist存储用户稍后输入的详细信息。如何检测应用程序的首次启动?我正在尝试使用NSUserDefaults,但我认为我做错了什么。
I am creating an app in which I have to create a plist when the app launches for the first time. I'm later going to use the plist to store details a user later inputs. How can I detect the first launch of the app? I was experimenting with NSUserDefaults but I think I'm doing something wrong.
推荐答案
您可以使用NSUserDefaults执行此操作。但要小心版本号。
You can do this with NSUserDefaults. But be careful with the Version Number.
执行以下操作:
NSString *bundleVersion = [[NSBundle mainBundle] objectForInfoDictionaryKey:(NSString *)kCFBundleVersionKey];
NSString *appFirstStartOfVersionKey = [NSString stringWithFormat:@"first_start_%@", bundleVersion];
NSNumber *alreadyStartedOnVersion = [[NSUserDefaults standardUserDefaults] objectForKey:appFirstStartOfVersionKey];
if(!alreadyStartedOnVersion || [alreadyStartedOnVersion boolValue] == NO) {
[self firstStartCode];
[[NSUserDefaults standardUserDefaults] setObject:[NSNumber numberWithBool:YES] forKey:appFirstStartOfVersionKey];
}
选择器firstStartCode只会在每个应用程序版本上按时调用第一次运行。
the selector firstStartCode will only be called on time for each application version on the very first run.
好吗?
这篇关于检测应用程序的第一次运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文