所以我得到了一个函数:
+ (NSString *)dataFilePath:(BOOL)forSave {
NSURL *url = [NSURL URLWithString:@"https://dl.dropbox.com/u/35612216/sample.xml"];
NSData *data = [NSData dataWithContentsOfURL:url]; // Load XML data from web
// construct path within our documents directory
NSString *applicationDocumentsDir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
NSString *storePath = [applicationDocumentsDir stringByAppendingPathComponent:@"sample.xml"];
// write to file atomically (using temp file)
[data writeToFile:storePath atomically:TRUE];
return [[NSBundle mainBundle] pathForResource:storePath ofType:@"xml"];
//return [[NSBundle mainBundle] pathForResource:@"sample" ofType:@"xml"];
}
这似乎不起作用,但是当我在我的项目(sample.xml)中添加一个支持文件并使用这一行时:
return [[NSBundle mainBundle] pathForResource:@"sample" ofType:@"xml"];
它会起作用的。但我需要从 url 而不是支持文件(资源文件)中获取我的 XML 数据
有人知道我该如何解决这个问题吗?