일부 값을 저장하기 위해 plist를 만들었지 만 테스트 중에 응용 프로그램이 닫힌 후에 새로 작성한 plist를 유지한다는 사실을 알고 있습니다. &이 멀티 태스킹에서 제거되었습니다. 그러나 그 응용 프로그램이 멀티 태스킹에서 제거되면 그 plist 내 값을 느슨하게하지만 애플 리케이션이 닫혀 있다면 ...plist를 유지하지만 plist 값이 손실 됨
이것은 내 plist 컨트롤러 클래스에서 모든 읽기/쓰기를 관리하는 데이터를 저장하는 방법입니다/등 저장
- (void) saveData:(NSString *)methodName signature:(NSString *)pSignature Version:(NSNumber *)pVersion request:(NSNumber *)rNumber dataVersion:(NSNumber *)dvReturned cacheValue:(NSNumber *)cValue;
{
// get paths from root direcory
NSArray *paths = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES);
// get documents path
NSString *documentsPath = [paths objectAtIndex:0];
// get the path to our Data/plist file
NSString *plistPath = [documentsPath stringByAppendingPathComponent:@"EngineProperties.plist"];
// set the variables to the values in the text fields
self.signature = pSignature;
self.version = pVersion;
self.request = rNumber;
self.dataVersion = dvReturned;
//do some if statment stuff here to put the cache in the right place or what have you.
if (methodName == @"manu")
{
self.man = cValue;
}
else if (methodName == @"models")
{
self.mod = cValue;
}
else if (methodName == @"subMod")
{
self.sub = cValue;
}
self.cacheValue = [NSDictionary dictionaryWithObjectsAndKeys:
man, @"Manu",
mod, @"Models",
sub, @"SubModels", nil];
NSDictionary *plistDict = [NSDictionary dictionaryWithObjectsAndKeys:
signature, @"Signature",
version, @"Version",
request, @"Request",
dataVersion, @"Data Version",
cacheValue, @"Cache Value", nil];
NSString *error = nil;
// create NSData from dictionary
NSData *plistData = [NSPropertyListSerialization dataFromPropertyList:plistDict format:NSPropertyListXMLFormat_v1_0 errorDescription:&error];
// check is plistData exists
if(plistData)
{
// write plistData to our Data.plist file
[plistData writeToFile:plistPath atomically:YES];
NSString *myString = [[NSString alloc] initWithData:plistData encoding:NSUTF8StringEncoding];
// NSLog(@"%@", myString);
}
else
{
NSLog(@"Error in saveData: %@", error);
// [error release];
}
}
@end
내 질문에 두 부분으로 .. 그들은 응용 프로그램이 multitaksing 표시 줄에서 제거에도 PLIST에 유지되도록 내가 값을 저장할 수 있습니다. 작동하는 경우 변경하려면 무엇을 변경해야합니까?
아마도 문제는 아니지만 사전에 writeToFile :을 호출하면 plist로 출력됩니다. –
파일 이름'EngineProperties.plist'에 저장하고 있지만, 여러분의 의견은'Data.plist'를 저장하고 있다고 생각합니다. 어떤 파일 이름을로드하고 있습니까? 또한 파일을 저장할 때'plistPath'를 기록하십시오. 시뮬레이터에서 앱을 실행하는 경우 파인더의 경로로 이동하여 생성 된 파일을보고 XCode에서 열어 내용을 볼 수 있습니다. – Dondragmer
opps 의견이 잘못되었습니다. 좀 더 기술적 인 이름으로 업데이트했습니다. 그러나 한 가지 질문은 파인더에서 경로가 어디에 있습니까? 전에 들어 본 적이 없습니까? –