我似乎偶然发现了一个关于从字符串中保存 xml 文件的问题(这是在 iPhone 上完成的)文件本身存在并包含在项目中(因此在工作区中),以及我从代码片段中获得的所有指示跟随在模拟器上没有任何错误的通过并在 iPhone 上失败(错误 513),但在任何一种情况下,文件都不会保存!
{
Hits = config->Hits;
NSString* filenameStr = [m_FileName stringByAppendingFormat: @".xml" ];
NSString* pData = [self getDataString]; // write xml format - checked out ok
NSError *error;
/* option 2 - does not work as well
NSBundle *mainBundle = [NSBundle mainBundle];
NSURL *xmlURL = [NSURL fileURLWithPath:[mainBundle pathForResource: m_FileName ofType: @"xml"]];
if(![pData writeToURL: xmlURL atomically: true encoding:NSUTF8StringEncoding error:&error])
{
NSLog(@"Houston - we have a problem %s@\n",[error localizedFailureReason]);
return false;
}
*/
if(![pData writeToFile: filenameStr atomically: FALSE encoding:NSUTF8StringEncoding error:&error])
{
NSLog(@"Houston - we have a problem %s@\n",[error localizedFailureReason]);
return false;
}
return true;
}
任何帮助将不胜感激,-A