[英]iPhone - How to download xml file in Documents directory
我必須解析一個xml文件,但是首先我必須下載它並將其存儲在我的/ Documents目錄中。 我怎樣才能做到這一點?
-(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;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.