ios - 更新现有 iOS 应用程序中的 sqlite 数据库

标签 ios sqlite core-data

所以我在 App Store 上有一个应用程序,其中包含一个包含大约 500 条记录的静态数据的 .sqlite 文件。当应用程序首次启动时,.sqlite 文件已复制到 NSDocumentDirectory, NSUserDomainMask

我计划为我的应用程序发布更新,并简单地向现有数据库添加大约 9 条新记录(没有结构更改)。

我努力寻找一种合适的方法来为次要更新执行此操作,但无法... 以下链接:Update/Insert content into an existing Sqlite db on an iPhone app update解释了开发人员将应用程序版本存储在数据库中并检查它以决定是否更新的机制......

感谢有关如何执行此操作的任何想法/帮助!提前致谢!

最佳答案

正如 Hot Licks 所说,在 DB 初始化后调用此代码:

if([self isFirstLaunchInCurrentVersion]){      
    //query the records you want to add , if records not exist, then insert them 

    [self setCurrentVersionLaunch:YES];
}

两个util方法:

- (BOOL)isFirstLaunchInCurrentVersion{
    NSString * currentVersion = [[[NSBundle mainBundle] infoDictionary] objectForKey:(NSString*)kCFBundleVersionKey];
    return  [[NSUserDefaults standardUserDefaults] boolForKey:currentVersion];
}
- (void)setCurrentVersionLaunched:(BOOL)isFirstLaunched{
    NSString * currentVersion = [[[NSBundle mainBundle] infoDictionary] objectForKey:(NSString*)kCFBundleVersionKey];
    [[NSUserDefaults standardUserDefaults] setBool:isFirstLaunched forKey:currentVersion];
    [[NSUserDefaults standardUserDefaults] synchronize];
}

关于ios - 更新现有 iOS 应用程序中的 sqlite 数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20509613/

相关文章:

ios - UITableViewCell 中具有第一响应者状态的 UITextField 是否会阻止单元格重复使用?

ios - 如果未显示图像,如何在顶部显示的标签上设置自动布局?

objective-c - Core Data 对相关对象的 NSSet 进行排序时出现问题

ios - UICollectionView reloadData 索引超出范围

ios - UIView 不遵守 UIScrollView 中的自动布局约束

ios - Facebook iOS iOS SDK登录错误

c - 如何使用 SQLite3 C 接口(interface)将 CSV 文件加载到主内存数据库中?

vb.net - 如何使用通配符搜索删除sqlite数据库中的表?

sql - sqlite3 : error?中的OR语句

ios - NSManagedObjectContext 给出错误请求 ";",我不确定为什么