I m a (kind of) newbie XCode programmer (well, 我想说的是,现在并不如此新的bie presentadays......) 和“my pet issue”是: ,“如果在我真正的iPad上出现麻烦,则把当地档案保存起来,而“”。
坦率地说,我对地方档案没有任何问题,但retrieving。 为什么? 由于在模拟材料中,我的当地档案似乎在汇编会议之间一直存在,但在实际装置上,每当申请启动时(不仅从X条码上载,而且通常发射),“文件”目录中的数据似乎消失了......。 因此,最后用户无法在闭会期间储存所需的历史数据。
Is it a perception of mine? Is it normal behaviour?
用于拯救这一“适当”数据的标准一是:
NSArray * paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString * documentsDir = [paths objectAtIndex:0];
NSString *finalPath=[NSString stringWithFormat:@"%@/%@", documentsDir, path];
NSLog(@"Course.m: updatePersistentObject (to disk): final file = %@",finalPath);
[NSKeyedArchiver archiveRootObject:newObject toFile:finalPath];
途径变量为@”。
代码一用于检索数据(无论是在boot时间还是操作时间),是:
NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSLog(@" historical data: Documents paths = %@", paths);
NSString * docsDir = [paths objectAtIndex:0];
NSLog(@"Course.m: loadHistoricalResultsData: docsDir vale [%@]", docsDir);
NSString *tmpPath=[NSString stringWithFormat:@"%@/.HistoricalTestResults", (NSString *)docsDir];
NSLog(@"Course.m: loadHistoricalResultsData: tmpPath vale [%@]", tmpPath);
NSFileManager *localFileManager = [[NSFileManager alloc] init];
// create directory if it doesn t exist, don t do anything if it exists... (?)
[localFileManager createDirectoryAtPath:tmpPath withIntermediateDirectories:YES attributes:nil error:nil];
NSDirectoryEnumerator *dirEnum = [localFileManager enumeratorAtPath:tmpPath];
NSString *file;
while (file = [ dirEnum nextObject])
{
NSLog(@"Historical Data Folder: %@", file);
if ( [[file pathExtension] compare:@"dat"] == NSOrderedSame )
{
NSString *filePath = [NSString stringWithFormat:@"%@/%@", tmpPath, file];
NSLog(@"Course.m: loadHistoricalResultsData: filePath vale [%@]", filePath);
mHistoricalTestList=[[NSKeyedUnarchiver unarchiveObjectWithFile:filePath] retain];
}
}
[localFileManager release];
My exact problem is that while on the simulator, AT BOOT TIME, if I put a trace on the "while" code line, I can see how the enumerator gets some value, and I can iterate among the found files. On the other hand, when using my iPad, the same breakpoint yields a "nil" pointer when obtaining the enumerator.
As I said, at the beginning of a clean program session, this is normal, so then I need to generate some storable results inside my program memory to store them onto disk. I do it, and then I write them (both inside the simulator and the iPad). Then I can even re-retrieve this data (from disk) and it seems to still exist inside the Documents folder (both onto the iPad and the simulator).
但是,如果我结束/选择方案,这种数据似乎在真实的iPad上消失,并且保留在模拟器中。
With this behaviour, my only deduction is "Real iPad programs cannot store persistent data onto their Documents directory". Am I right? (Of course not, because I ve seen it work on some other programs). So I have the feeling I m doing something wrong, and after wasting TONS of time trying to find it, I m now asking for advice on stackoverflow...
每次帮助/帮助/帮助/帮助/帮助都不会受到欢迎。