我要解析一个xml文件,但首先我必须下载并存储在我的/ Documents目录中。我怎么能这样做?
答案 0 :(得分:0)
-(NSString *)downloadXML:(NSString *)path newFileName:(NSString *)newFileName {
//NSLog(@"\nENTRATO NEL METODO DI DOWNLOAD");
NSURL *URL = [NSURL URLWithString:[path stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding]];
NSData *xmlData = [NSData dataWithContentsOfURL:URL];
if(xmlData == nil) {
// Error - handle appropriately
}
NSString *applicationDocumentsDir=[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
NSString *storePath=[applicationDocumentsDir stringByAppendingPathComponent:newFileName];
[xmlData writeToFile:storePath atomically:TRUE];
//NSLog(@"\nFINITO IL METODO DI DOWNLOAD");
return storePath;
}