主应用程序及其扩展程序之间共享 ObjectBox 数据库
我试图在应用程序及其扩展之间共享 Objectbox 创建的数据库。 我使用下面的代码在应用程序及其扩展之间共享数据库。
static func storeURL() -> URL {
guard let fileContainer = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: "AppGroupName") else {
fatalError("Shared file container could not be created.")
}
return fileContainer.appendingPathComponent("\(databaseName)")
}
当应用程序在前台运行时,该应用程序工作正常。当应用程序进入后台时,应用程序就会崩溃。当我删除上面的代码并使用下面的代码时,
let appSupport = try FileManager.default.url(for: .documentDirectory,
in: .userDomainMask,
appropriateFor: nil,
create: true)
.appendingPathComponent(Bundle.main.bundleIdentifier!)
let directory = appSupport.appendingPathComponent(databaseName)
应用程序不会崩溃,并且在没有数据库共享的情况下开始正常工作。
注意:如果我们忽略此崩溃,我就可以使用应用程序及其扩展中的数据库。
I was trying to share the Objectbox created database between the app and its extension.
I used the below code to share the database between the app and its extension.
static func storeURL() -> URL {
guard let fileContainer = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: "AppGroupName") else {
fatalError("Shared file container could not be created.")
}
return fileContainer.appendingPathComponent("\(databaseName)")
}
The app is working fine when the app is running in foreground. When the app goes to the background then the app is crashing. When I remove the above code and used the below code
let appSupport = try FileManager.default.url(for: .documentDirectory,
in: .userDomainMask,
appropriateFor: nil,
create: true)
.appendingPathComponent(Bundle.main.bundleIdentifier!)
let directory = appSupport.appendingPathComponent(databaseName)
The app does not crash and started working fine without Database sharing.
Note: If we ignore this crash, I was able to use the database from the app and its extension.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论