iPhone - How to download xml file in Documents directory
i've to parse an xml file, but at first i have to download it and store in my /Documents 开发者_如何学Cdirectory. How can i do this?
-(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;
}
精彩评论