0

我必须解析一个 xml 文件,但首先我必须下载它并存储在我的 /Documents 目录中。我怎样才能做到这一点?

4

1 回答 1

0
-(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;

}
于 2011-08-31T19:20:39.757 回答