2016-04-07 4 views
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); 
} 

Antwort

0

Sie können nur die XML-Datei in Ihrem Projekt-Explorer ziehen und es wird ein Teil des Pakets sein, wenn Sie/install führen Sie es

+0

Danke. Das habe ich mir auch gedacht, aber ich muss etwas vermissen, weil ich immer noch nicht zur Akte komme. – 56phil

+0

Den Code posten? Vielleicht machen Sie etwas falsch mit dem Zugriff auf die Datei? – StealthOne