0

AppDelegateのにifステートメントがありapplication DidFinishLaunchingWithOptionsます。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;
}
4

1 に答える 1

2

NSUserDefaultsアプリを再構築したときにクリアされないこの値を保存しています。この番号をリセットするには、シミュレーターまたはデバイスからアプリをアンインストールして再構築する必要があります。

ポイントNSUserDefaultsは、それが本当に永続的であるということです。アプリケーションがアプリストアから更新されても保持されます。データをクリアする2つの方法は、参照しているキーを具体的かつ意図的に削除するか、アプリを削除することです。

さらに、以下に示すように、私はあなたのためにいくつかの微調整を行いました:

- (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;
}
于 2012-09-04T01:38:15.437 に答える