0
Ich habe eine App in Entwicklung, die eine XML-Datei benötigt. Die App funktioniert gut im Simulator. Es schlägt jedoch auf einem tatsächlichen Gerät fehl, da keine Datei vorhanden ist. Wie mache ich diese Datei Teil des Pakets?XML-Datei in iOS-App übertragen
NSFileManager *fm = [NSFileManager defaultManager];
NSArray *directoryPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *directoryPath = [directoryPaths objectAtIndex:0];
NSString *path = [NSString stringWithFormat:@"%@/games.xml", directoryPath];
NSLog(@"%@", path);
if ([fm fileExistsAtPath:path]) {
self.games = [[NSArray alloc] initWithContentsOfFile:path];
NSLog(@"Found %lu games on device.", (unsigned long)self.games.count);
} else {
NSData *data = [[NSData alloc] initWithContentsOfFile:@"/Users/philHuffman/dev/Games.xml"];
[fm createFileAtPath:path contents:data attributes:nil];
self.games = [[NSArray alloc] initWithContentsOfFile:path];
NSLog(@"Found %lu games in file on the mac.", (unsigned long)self.games.count);
}
Danke. Das habe ich mir auch gedacht, aber ich muss etwas vermissen, weil ich immer noch nicht zur Akte komme. – 56phil
Den Code posten? Vielleicht machen Sie etwas falsch mit dem Zugriff auf die Datei? – StealthOne