问题描述
我正在使用swift开发适用于iOS的应用程序,并选择Realm作为数据库。我实现了如下所述,它将在AppDelegate.swift中首次使用该应用程序时复制默认数据。
func application(_ application: UIApplication,didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
let defaultRealmPath = Realm.Configuration.defaultConfiguration.fileURL!
let bundleRealmPath = Bundle.main.url(forResource: "Seed",withExtension: "realm")
if !FileManager.default.fileExists(atPath: defaultRealmPath.path) {
do {
try FileManager.default.copyItem(at: bundleRealmPath!,to: defaultRealmPath)
} catch let error {
print("error: \(error)")
}
}
return true
}
如果这是用户首次使用此应用,则应复制默认数据。 但是,如果我在iOS 13上进行了测试,则可以成功复制它,但是在iOS 11上,则不能复制。
如果在iOS 13中,“ FileManager.default.fileExists(atPath:defaultRealmPath.path)”的结果为“ false”(=文件不存在),但在iOS 11中,则“ FileManager.default”的结果.fileExists(atPath:defaultRealmPath.path)”为“ true”。
为什么会发生这种情况,我该如何解决这个问题?
我的领域版本是5.1.0。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)