Locally stored data files are saved in the emulator, but not in a real iPad device ... I got lost

I am a (programmer) Xcode programmer (well, I would say that now is not so new ...) and "my home problem": "I have problems saving local files on my real iPad, compared to saving them with a simulator .

Well, to be honest, I have no problem with SAVING local files, but recovering them. What for? Since on the simulator my local files seem to be saved between compilation sessions, but on the real device every time the application starts (not only after downloading it from Xcode, but it usually starts), the data in the Documents directory seems to disappear .. Thus, the end user will not be able to store the necessary historical data between sessions.

Is that my perception? Is this normal behavior?

The code I use to save this “persistent” data is as follows:

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];

'path' variable is @ ". HistoricalTestResults";

The code I use to retrieve data (for example, at boot time or at runtime) is as follows:

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];

, AT BOOT TIME, while, , , . , iPad "nil" .

, , , . , ( , iPad). ( ) , , "" ( iPad, ).

, / , , , iPad .

: " iPad " ". ? (, , , ). , - , , , , stackoverflow...

// .

+3
2

! (!!?).

, , , " ", , , , . ( )

, " " ( ), . , , ( ):

NSFileManager *localFileManager = [[NSFileManager alloc] init];

NSString *tmpPath=[NSString stringWithFormat:@"%@/.HistoricalTestResults", (NSString *)docsDir];

NSDirectoryEnumerator *dirEnum = [localFileManager enumeratorAtPath:tmpPath];
// create directory if it doesn't exist, don't do anything if it exists... (?)
[localFileManager createDirectoryAtPath:tmpPath withIntermediateDirectories:YES attributes:nil error:nil];

( ), ( ):

NSString *tmpPath=[NSString stringWithFormat:@"%@/.HistoricalTestResults", (NSString *)docsDir];

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];

, " , ". , "createDirectoryAtPath" "" , ...

, , , , !

!

0

-, , - , . , , dir , ipad , , , .

, , , , , . .Strings iphone .strings. , LocalizedString().

, tl; dr: , , .

, . !

PS: Gaudí rlz.

+3
source

Source: https://habr.com/ru/post/1789536/


All Articles