【问题标题】:iPhone - How to download xml file in Documents directoryiPhone - 如何在 Documents 目录中下载 xml 文件
【发布时间】:2011-09-01 03:20:39
【问题描述】:

我必须解析一个 xml 文件,但首先我必须下载它并存储在我的 /Documents 目录中。我该怎么做?

【问题讨论】:

    标签: xml parsing download documents


    【解决方案1】:
    -(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;
    
    }
    

    【讨论】:

      猜你喜欢
      • 2012-11-02
      • 2017-02-13
      • 1970-01-01
      • 1970-01-01
      • 2012-02-16
      • 2011-03-13
      • 2012-03-10
      • 1970-01-01
      • 2013-11-27
      相关资源
      最近更新 更多