开发者

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;

}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜