응용 프로그램이 닫힐 때 간단한 .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];
}
시뮬레이터에있는이 잘 작동하지만,를
이
내 코드입니다 장치 ... 어디에 문제가 있습니까? 감사합니다 ...
는 당신은 확실히보기가로드 있습니까? 보기가 표시되지 않으면 장치의 메모리가 압니까 장치가 언로드 될 수 있습니다. – Jonah
네, 꽤 확신합니다 .. 어쨌든 내 앱의 뷰는 두 가지 뿐이며, 둘 사이를 전환 할 때 언로드되지 않으므로 이것이 버그의 원인이라고 생각하지 않습니다 .. – Lolloz89
어리석은 질문이지만 iOS 4 이상을 실행하고 있습니까? – jbat100