- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在 App Delegate 的 application DidFinishLaunchingWithOptions
中有一个 if 语句。即使 if 语句不正确,if 语句中的代码也会运行。难道我做错了什么?它似乎只是忽略了 if 语句。
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSInteger i = [[NSUserDefaults standardUserDefaults] integerForKey:@"numOfLCalls"];
[[NSUserDefaults standardUserDefaults] setInteger:i+1 forKey:@"numOfLCalls"];
if (i >= 3) {
UIAlertView *alert_View = [[UIAlertView alloc] initWithTitle:@"Hey! You are still coming back!" message:@"It would mean a whole lot to me if you rated this app!" delegate:self cancelButtonTitle:@"Maybe later" otherButtonTitles: @"Rate", nil];
[alert_View show];
}
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;
}
最佳答案
您将此值存储到 NSUserDefaults
中,当您重建应用程序时它不会被清除。要重置此数字,您必须从模拟器或设备上卸载该应用程序并重新构建。
NSUserDefaults
的要点在于它是真正持久的。即使您的应用程序已从应用程序商店更新,它仍将保留,清除其数据的唯一两种方法是专门有意地删除您引用的 key ,或删除应用程序。
此外,正如您在下面看到的,我为您做了一些细微的调整:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
if (![[NSUserDefaults standardUserDefaults] integerForKey:@"numOfLCalls"]) {
[[NSUserDefaults standardUserDefaults] setInteger:1 forKey:@"numOfLCalls"];
}else{
NSInteger i = [[NSUserDefaults standardUserDefaults] integerForKey:@"numOfLCalls"];
[[NSUserDefaults standardUserDefaults] setInteger:i++ forKey:@"numOfLCalls"];
}
if (i >= 3) {
UIAlertView *alert_View = [[UIAlertView alloc] initWithTitle:@"Hey! You are still coming back!" message:@"It would mean a whole lot to me if you rated this app!" delegate:self cancelButtonTitle:@"Maybe later" otherButtonTitles: @"Rate", nil];
[alert_View show];
}
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;
}
关于ios - 应用程序 didFinishLaunchingWithOptions 忽略 if 语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12255713/
所以我尝试使用此方法根据用户在设置包中选择的内容加载特定主题。当我插入 NSLog 时,它将加载默认的它们(现代主题),但它永远不会更改为粉红色主题。 每次启动应用程序时都会加载此方法,即使应用程序仍
iOS 4 用户正在使用我的应用程序并使其在后台运行,有新版本可用,并且用户从 App Store 下载该新版本。 下载并安装新版本后,我的应用程序是否会退出并重新启动,以便我可以确保 didFini
我在启用推送通知时遇到问题。 使用此代码,我尝试启用通知: - (BOOL)application:(UIApplication *)application didFinishLaunchingWit
我嵌入到一个环境 (Adobe AIR) 中,无法覆盖 didFinishLaunchingWithOptions。还有其他方法可以获得这些选项吗?它们是否存储在某个全局变量中?或者有人知道如何在 A
我在现有项目中面临一个奇怪的问题。 从早上开始,我就面临着来自火力基地的一次奇怪的崩溃。 它工作正常,没有任何问题,但从早上开始我就面临这个问题。 崩溃: *** Terminating app du
我附上了两个调用方法的线程,该方法应始终在主线程上运行: 这导致了崩溃,因为我正在尝试创建持久存储协调器。 最佳答案 堆栈具有误导性。崩溃与 didFinishLaunchingWithOptions
在 didFinishLaunchingWithOptions 中,您如何知道应用程序是从前台恢复还是新启动?我需要知道这个方法,因为有 2 个任务要运行,具体取决于 launchOptions 是什
我正在我的应用程序中实现推送通知,并且当应用程序打开时一切正常:收到通知时,我的方法 [self processRemoteNotification:pushNotification] 按预期触发。现
didFinishLaunchingWithOptions` 做了什么以及何时调用它? 此外,我正在寻找类似 Android 中的“事件生命周期”图表的图表。如果您知道,请分享。 最佳答案 应用委托(
我觉得我应该知道这一点,但我不知道,这总是让我感到困惑。 浏览示例代码和教程时,我有时会看到 AppDelegates 有一个 @property UIWindow* 窗口, 然后是 @synthes
我想知道如何在应用更新下载后再次调用 didFinishLaunchingWithOptions,因为我所有的函数调用都在那里。 我需要再次调用它 self.dataArray = [self rea
我已经从后台终止了该应用程序。终止应用程序后,我发送一个推送通知。我对将要调用的 AppDelegate 函数有两个疑问: 1。 didFinishLaunchingWithOptions 会被调用吗
当我发送推送通知并且我的应用程序处于打开状态或在后台并单击推送通知时,我的应用程序将重定向到 PushMessagesVc viewController (如预期的那样) 我使用如下代码: -(voi
在为 iOS 开发时,您应用的第一个入口点是 -[AppDelegate application:didFinishLaunchingWithOptions:]。此方法的返回类型是 BOOL。默认情况
我对显示本地通知有相当大的理解问题。据我在其他线程中阅读,首先使用应用程序创建并安排本地通知。 要显示该通知,必须使用委托(delegate) didFinishLaunchingWithOption
我正在将文件导出为 NSData 对象并将它们的文件类型与我的应用相关联。 然后我可以通过在设备上打开邮件来导入文件,然后单击该文件并使用它打开应用程序。 但是,这样做时我无法从 XCode 启动应用
我只是想在 didFinishLaunchingWithOptions 中显示带有动画的 View ,我的代码如下: - (BOOL)application:(UIApplication *)appl
我在 didFinishLaunchingWithOptions 中有这段代码: self.window = [[UIWindow alloc] initWithFrame:[[UIScreen ma
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launc
我在应用程序一开始就有以下内容:didFinishLaunchingWithOptions: - (BOOL)application:(UIApplication *)application didF
我是一名优秀的程序员,十分优秀!