[英]How to determine that user runs the app for the first time?
I got a problem of my iOS app recently. 我最近遇到了iOS应用程序的问题。 In my app, an instruction view will appear at the first time of running, then hide from then on.
在我的应用程序中,一个指令视图将在第一次运行时出现,然后从那时开始隐藏。 How can I implement this effect?
我该如何实现这种效果?
Try to use this function: 尝试使用此功能:
- (BOOL) isFirstRun
{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
if ([defaults objectForKey:@"isFirstRun"])
{
return NO;
}
[defaults setObject:[NSDate date] forKey:@"isFirstRun"];
[[NSUserDefaults standardUserDefaults] synchronize];
return YES;
}
In your app delegate check for a key in the user defaults (your own custom key, something like "AppWasAlreadyStartedPreviously"). 在您的应用程序委托中检查用户默认值中的密钥(您自己的自定义密钥,类似“AppWasAlreadyStartedPreviously”)。 If the key doesn't exist yet, it's the first run.
如果密钥尚不存在,则是第一次运行。 You can show your instruction view and add the key to the user defaults.
您可以显示指令视图并将密钥添加到用户默认值。 The next time the user starts the app you'll find the key in the user defaults and know that it's not the first run.
下次用户启动应用程序时,您将在用户默认值中找到该键,并知道它不是第一次运行。
See the documentation of NSUserDefaults . 请参阅NSUserDefaults的文档。
Store a file and check if the file exsists every time when you start the app. 存储文件并检查每次启动应用程序时文件是否存在。 If tr file does not exsists then show intro, and then create the file.
如果tr文件不存在则显示介绍,然后创建该文件。
我认为唯一的方法是将值存储到指定的文件中,在运行应用程序时,您应首先检查该值,然后您可以处理应用程序是否已运行的结果。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.