开发者

iPhone - How to download xml file in Documents directory

开发者 https://www.devze.com 2023-02-26 04:58 出处:网络
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 *)n

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

精彩评论

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