2011-10-13 2 views
2

응용 프로그램이 닫힐 때 간단한 .plist 파일에 간단한 문자열을 저장하려고합니다.applicationWillResignActive 알림이 장치에서 캐치되지 않음

- (void)viewDidLoad { 
NSString *filePath = [self dataFilePath]; 
if ([[NSFileManager defaultManager] fileExistsAtPath:filePath]) { 
    NSMutableArray *array = [[NSMutableArray alloc] initWithContentsOfFile:filePath]; 
    self.kmOld.text = [array objectAtIndex:0]; 

    [array release]; 
} 


[[NSNotificationCenter defaultCenter] addObserver:self 
             selector:@selector(applicationWillResignActive:) 
             name:UIApplicationWillResignActiveNotification 
             object:NULL]; 
[super viewDidLoad]; 

}

는 그 다음 applicationWillResignActive 방법은 다음과 같습니다 : 그것을 무시하는 것 같다

- (void)applicationWillResignActive:(NSNotification *)notification { 

    NSString *text = [[NSString alloc]initWithFormat:@"%@",kmNew.text]; 
    NSLog(@"%@",text); 

    if ([text intValue]>0) { 
     NSArray *array = [[NSArray alloc] initWithObjects:text, nil]; 

     BOOL success = [array writeToFile:[self dataFilePath] atomically:YES]; 
     NSLog(@"%d",success); 
     [array release]; 
    } 
    [text release]; 
} 

시뮬레이터에있는이 잘 작동하지만,를

내 코드입니다 장치 ... 어디에 문제가 있습니까? 감사합니다 ...

+0

는 당신은 확실히보기가로드 있습니까? 보기가 표시되지 않으면 장치의 메모리가 압니까 장치가 언로드 될 수 있습니다. – Jonah

+0

네, 꽤 확신합니다 .. 어쨌든 내 앱의 뷰는 두 가지 뿐이며, 둘 사이를 전환 할 때 언로드되지 않으므로 이것이 버그의 원인이라고 생각하지 않습니다 .. – Lolloz89

+0

어리석은 질문이지만 iOS 4 이상을 실행하고 있습니까? – jbat100

답변

8

UIApplication 수명주기에 대한 개요는 http://www.cocoanetics.com/2010/07/understanding-ios-4-backgrounding-and-delegate-messaging/을 참조하십시오. 앱이 실행중인 iOS 버전과 앱 종료/실행 원인에 따라 올바른 알림을 수신하지 못하고 UIApplicationWillTerminateNotification을 준수해야 할 수도 있습니다. 그 통지를 보낼 때

iOS <4

iOS 4+

+0

감사합니다! 이것은 (장치에) 도움이되었다. 그래서 iOs 4+와 3.x에서 지원되는 app을 개발한다면 applicationWillResignActive와 applicationWillTerminate 메소드를 모두 구현해야 하는가? – Lolloz89

+0

맞습니다. 두 경우 모두 고려해야합니다 (사임 및 종료). – Jonah

관련 문제