简体   繁体   English

如何确定用户第一次运行应用程序?

[英]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.

相关问题 Swift:首次运行应用程序时,如何将文件从应用程序包复制到“文档”文件夹 - Swift: How to copy files from app bundle to Documents folder when app runs for first time 如何在应用程序第一次运行时在我的iOS应用程序中打开页面视图控制器? - How to open a page view controller in my iOS app only the first time the app runs? 确定哪个UIViewController首先运行 - Determine which UIViewController runs first 如何检查用户是否首次访问我的iOS应用? - How to check if user visit my iOS app for the first time? Applepay-canMakePaymentsUsingNetworks首次运行应用程序时返回“否”。 - Applepay - canMakePaymentsUsingNetworks returns NO for the first time app runs. Swift 中是否有仅在第一次打开应用程序时运行的功能? - Is there a function in Swift that only runs during the first time opening the app? 如何确定 UIViewController 是第一次启动? - How to determine that UIViewController was started for the first time? 如何确定我的应用是第一次从AppStore下载? - How do I determine that my app was just downloaded from AppStore the first time? Facebook iOS SDK - 如何确定用户是否已删除应用程序而不是每次都调用授权? - Facebook iOS SDK - how to determine if user has deleted app without calling authorize each time? 首次应用徒步旅行者之旅 - Walking Tour for the first time app user
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM