Note that there are some explanatory texts on larger screens.

plurals
  1. POLocally saved data files are persistant in the emulator but not in the real iPad device... I'm lost
    text
    copied!<p>I'm a (kind of) newbie XCode programmer (well, I would say not so newbie nowadays...) and "my pet issue" is: <strong>"I'm having trouble saving local files onto my real iPad, compared to saving them with the simulator"</strong>.</p> <p>Well to be honest, I have no problem whatsoever SAVING local files, but <em>retrieving</em> them. Why? Because on the simulator my local files seem to persist between compilation sessions, but on the real device, every time the application gets launched (not only after being uploaded from Xcode, but normally launched), data inside the "Documents" directory seems to disappear... So the final user would not be able to store needed historical data between sessions.</p> <p>Is it a perception of mine? Is it normal behaviour? </p> <p>The code I use to save this "persistent" data is this one:</p> <pre><code>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]; </code></pre> <p>'path' variable being @".HistoricalTestResults";</p> <p>The code I use to retrieve data (wheather at boot time, or at runtime) is this one:</p> <pre><code>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]; </code></pre> <p>My exact problem is that while on the simulator, <strong>AT BOOT TIME</strong>, 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.</p> <p>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).</p> <p>But then, if I close/kill the program, this data seems to be lost onto the real iPad, and to persist in the simulator.</p> <p>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...</p> <p>Every piece of help/insight/hint will be more than welcome.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload