从URL下载XML文件并保存

时间:2016-01-28 19:07:40

标签: ios objective-c xml

我想下载一个在GitHub中共享的xml文件。这是我的代码,但我的结果是网站的xml。我哪里错了?

这是我的代码:

    NSString *urlToDownload = @"https://github.com/qazaleh/xml-file/blob/master/result.xml";
    NSURL  *url = [NSURL URLWithString:urlToDownload];
         NSData *urlData = [NSData dataWithContentsOfURL:url];
         if ( urlData )
         {
            NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
            NSString  *documentsDirectory = [paths objectAtIndex:0];
            NSString  *filePath = [NSString stringWithFormat:@"%@/%@", documentsDirectory,@"result"];
            NSLog(@"Downloading Started %@",filePath);
             //saving is done on main thread
                 [urlData writeToFile:filePath atomically:YES];
         }
}

0 个答案:

没有答案