2012-09-04 1 views
0

if 응용 프로그램 대리인의 application DidFinishLaunchingWithOptions에 if 문이 있습니다. if 문이 참이 아니더라도 if 문의 코드가 실행됩니다. 내가 뭔가 잘못하고 있는거야? if 문을 무시하는 것 같습니다.응용 프로그램 didFinishLaunchingWithOptions 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; 
} 
+0

: 나는 당신을 위해 약간의 비틀기 몇했습니다 아래 당신이 볼 수 또한

? –

+0

@NDPostWhenIdle 나는 그것을 시도하지 않았지만, 방금 전 콘솔 출력을 보았습니다. 6. 어떻게 또는 왜 그런 일이 일어 났는지 전혀 모른다. –

+0

그래,'i> = 3' 조건은 참이지만 경고는 표시되지 않고 있습니까? –

답변

2

이 값은 NSUserDefaults에 저장되며 앱을 다시 작성할 때 지워지지 않습니다. 이 번호를 재설정하려면 시뮬레이터 나 장치에서 앱을 제거하고 다시 빌드해야합니다.

NSUserDefaults의 요점은 진정으로 지속된다는 것입니다. 앱 스토어에서 앱이 업데이트 되더라도 그대로 유지되며 데이터를 지우는 두 가지 방법은 참조하는 키를 구체적으로 또는 의도적으로 삭제하거나 앱을 삭제하는 것입니다. 당신이 "나는"제대로 증가 않는 로그인하면

- (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; 
} 
관련 문제