iOS - 创建数据库模式(只运行一次代码) [英] iOS - Create Database Schema (Run code only once)
问题描述
我为我的iPhone应用程式资料库使用 FMDB ,而且我想建立资料库和表格架构只有一次。
I'm using FMDB for my iPhone App database and i want to create the database and tables schema only once.
当用户安装或更新应用程序时,如何运行OBJC代码?
How can i run OBJC code when the user installs or updates the app?
推荐答案
您可以在 NSUserDefaults
- NSUserDefaults
仅在用户删除应用程序时重置,因此,如果在用户默认值中找不到特定的布尔值,则会执行一些代码(然后在执行后保存该值,以防止它会再次运行)。
You can set a boolean value in NSUserDefaults
- NSUserDefaults
is only reset when the user deletes the app, so you have some code that executes if a particular boolean value is not found in the user defaults (and then saves that value after execution to prevent it from being run again).
这将覆盖你的普通运行代码一次安装场景 - 你可以实现相同的更新与类似的方法,但利用 CFBundleVersion
变量(对于您的应用程序的每个版本都会有所不同)。
That will cover your plain 'run code once upon install' scenario - you can achieve the same for updates with a similar approach, but utilising the CFBundleVersion
variable (which will be different for each version of your app).
这篇关于iOS - 创建数据库模式(只运行一次代码)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!