gpt4 book ai didi

ios - 应用程序 didFinishLaunchingWithOptions 忽略 if 语句

转载 作者:行者123 更新时间:2023-11-28 22:49:55 26 4
gpt4 key购买 nike

我在 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com