gpt4 book ai didi

iOS 下载 sqlite 数据库并替换现有数据库

转载 作者:行者123 更新时间:2023-11-28 18:42:50 25 4
gpt4 key购买 nike

我必须下载数据库并替换沙盒中的现有数据库:这是执行此操作的可能方法:

DBHelpers *help=[[DBHelpers alloc] init];


NSString *targetPath=[[help DocumentsDirectory] stringByAppendingPathComponent:DATABASE_NAME];


NSLog(@"Target path: %@", targetPath);
NSFileManager *fileManager=[NSFileManager defaultManager];

//if([fileManager fileExistsAtPath:targetPath])
//{
// NSLog(@"Exists");
// return;
}
NSString *sourcePath=[help PathForResource:DATABASE_NAME];
NSLog(@"SourcePath path: %@", sourcePath);
NSError *error;
NSData *data=[NSData dataWithContentsOfURL:[NSURL URLWithString:@"www.hello.com/mydb.sqlite"]];
[data writeToFile:targetPath atomically:NO];

// [fileManager copyItemAtPath:sourcePath toPath:targetPath error:&error];
NSLog(@"Error %@", error);

最佳答案

考虑以下步骤:

NSData *fetchedData = [NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://www.myserver.com/files/DBName.sqlite"]]];
NSString *documentsPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDire ctory, NSUserDomainMask, YES) lastObject];
NSString *filePath = [documentsPath stringByAppendingPathComponent:@"DBName.sqlite"];
[fetchedData writeToFile:filePath atomically:YES];

来自 iphonedevsdk forum线程。

关于iOS 下载 sqlite 数据库并替换现有数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9132684/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com