0
我必須解析一個xml文件,但首先我必須下載它並存儲在我的/ Documents目錄中。我怎樣才能做到這一點?iPhone - 如何下載文件目錄中的xml文件
我必須解析一個xml文件,但首先我必須下載它並存儲在我的/ Documents目錄中。我怎樣才能做到這一點?iPhone - 如何下載文件目錄中的xml文件
-(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;
}