在iphone上下载并存储文件

时间:2009-11-28 15:01:13

标签: iphone download

我想用我的服务器上用于更新的sqlite替换我在iphone上的sqlite数据库存储。 我怎么能这样做?我可以下载并使用NSData对象获取它但是如何将其存储在iphone上然后替换旧的? 感谢

1 个答案:

答案 0 :(得分:2)

这很简单。它应该是这样的:

NSData *fetchedData = ...;    /* downloaded using NSURLConnection or whatever*/
NSString *documentsPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
NSString *filePath = [documentsPath stringByAppendingPathComponent:@"DBName.sqlite"];

[fetchedData writeToFile:filePath atomically:YES];