views:

40

answers:

1

Hi, I have a problem. I have the code below for save a data on file. I build my app on the device, and run. The result variable is TRUE, but i don't find the file on the my iPhone device. Can you help me? Thank and sorry for my english XP

 -(void)saveXML:(NSString*)name:(float)x:(float)y:(float)z{

    NSMutableData *data = [NSMutableData data];
    NSKeyedArchiver *archiver = [[NSKeyedArchiver alloc] initForWritingWithMutableData:data];
    [archiver setOutputFormat:NSPropertyListXMLFormat_v1_0];
    [archiver encodeFloat:x forKey:@"x"];
    [archiver encodeFloat:y forKey:@"y"];
    [archiver encodeFloat:z forKey:@"z"];
    [archiver encodeObject:name forKey:@"name"];
    [archiver finishEncoding];
    NSString* filePath = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0] stringByAppendingPathComponent:@"XML Position"];
    BOOL result = [data writeToFile:filePath atomically:YES];
    if(result)
        [self   updateTextView:@"success"];
    [archiver release];

 }
A: 

On the device, the corresponding code:

NSString* filePath = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0] stringByAppendingPathComponent:@"XML Position"];

gives the following value to filePath:

/var/mobile/Applications/<<UUID>>/Documents/XML Position

where UUID is the unique application identifier.

Laurent Etiemble
UUiD like UDID?
zp26
NSString* filePath = @"/var/mobile/Applications/<<myApplicationIdentifier>>/Documents/XML Position"; but isn't correct
zp26
@zp26: Don't try and use an absolute path. Use the same methods in the question (i.e., NSSearchPathForDirectoriesInDomain) to construct the path back to the file.
Jason Coco