需要明确的是,当前无法使用Realm在iOS应用程序和Messages扩展之间拥有单个共享数据库吗?
It is very much possible
For Swift 3
I used the following code to share Realm db between app and app extension:
let sharedDirectory: URL = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: "group.your.app")! as URL
let sharedRealmURL = sharedDirectory.appendingPathComponent("db.realm")
Realm.Configuration.defaultConfiguration = Realm.Configuration(fileURL: sharedRealmURL)
Just call this code from didFinishLaunchingWithOptions
of AppDelegate
and viewDidLoad
of MSMessagesAppViewController
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.