2010-05-29 58 views
1

我遇到了问题。 我有下面的代码保存文件上的数据。 我在设备上构建我的应用程序,然后运行。 结果变量为TRUE,但我没有在我的iPhone设备上找到该文件。 你能帮我吗? 感谢和抱歉,我的英语水平XP寻找iPhone上的日志文件

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

} 
+0

[saveToFile问题]的可能重复(http://stackoverflow.com/questions/2934368/problem-with-savetofile) – kennytm 2010-05-29 09:17:02

+0

这是一个不同的问题。 – zp26 2010-05-29 09:21:59

回答

0

在设备,相应的代码:

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

给出以下值filePath

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

其中UUID是独特的应用标识符。

+0

UUiD像UDID? – zp26 2010-05-29 10:33:39

+0

NSString * filePath = @“/ var/mobile/Applications/<< myApplicationIdentifier >>/Documents/XML Position”;但不正确 – zp26 2010-05-29 10:39:10

+0

@ zp26:不要尝试使用绝对路径。在问题中使用相同的方法(即NSSearchPathForDirectoriesInDomain)将路径构造回文件。 – 2010-05-29 10:46:41