如何将iMessage扩展的sqlite存储文件下载到MacBook

我们正在开发一个iMessage扩展。 它成功地使用了Core Data。 我们需要评估store.sqlite文件,但是找不到它。

我们试图find这样的:

  • 在Xcode:窗口 – >设备
  • Installed Apps ,select我们的扩展
  • Download Container ...

但是容器是空的:


更新:

感谢@ Mundi的回答,我们发现了如何获取模型URL:

file:///var/mobile/Containers/Data/PluginKitPlugin/9C15B67C-8917-4A24-9FB0-BD119C43B3C4/Library/Application%20Support/Model.sqlite

现在我们试图将模型复制到Documents文件夹,以便能够通过Xcode将其下载到我们的MacBook(请参阅上文)。

不幸的是,“文件:

 NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0] 

再次在/var/mobile/Containers/

 file:///var/mobile/Containers/Data/PluginKitPlugin/D0BBD375-A8B7-43DD-8486-1909965CAEB0/Documents 

我们如何将Model.sqlite文件从共享容器下载到我们的MacBook?

最好的办法就是用邮件共享操作书写出口商。 在我的一个应用程序中,我允许用户通过电子邮件发送一份sqlite文件来导出所有的数据。

 func exportAllDataSqlite() { let documentsUrl = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first! var newFilePath: URL! var mutablePathComponents = [String]() var sqliteFileCopied = false do { let directoryContents = try FileManager.default.contentsOfDirectory(at: documentsUrl, includingPropertiesForKeys: nil, options: FileManager.DirectoryEnumerationOptions()) for f in directoryContents { let pathComponents = f.pathComponents if pathComponents.last == "XXXXWhatever your file is called when created by the persisten store.sqliteXXXXX" { //create a copy of the file with a dated file name mutablePathComponents = pathComponents let dateComponents = (Calendar.current as NSCalendar).components([.day, .month, .year], from: Date()) let dateString = "\(dateComponents.day)-\(dateComponents.month)-\(dateComponents.year)" mutablePathComponents[mutablePathComponents.count-1] = "Events App \(dateString).sqlite" newFilePath = NSURL.fileURL(withPathComponents: mutablePathComponents) do { try FileManager.default.copyItem(at: f, to: newFilePath!) sqliteFileCopied = true print("Copied sqlite file") } catch let error as NSError { print(error.localizedDescription) } } } } catch let error as NSError { print(error.localizedDescription) } if sqliteFileCopied == true { //sharing let activityItem:URL = newFilePath! let objectsToShare = [activityItem] let activityVC = UIActivityViewController(activityItems: objectsToShare, applicationActivities: nil) activityVC.completionWithItemsHandler = { activity, success, items, error in do { try FileManager.default.removeItem(at: newFilePath!) print("Deleted file: \(newFilePath!)") } catch let error as NSError { print(error.localizedDescription) } } let excludeActivities = [UIActivityType.airDrop, UIActivityType.print, UIActivityType.assignToContact, UIActivityType.saveToCameraRoll, UIActivityType.addToReadingList, UIActivityType.postToFlickr, UIActivityType.postToVimeo] activityVC.excludedActivityTypes = excludeActivities self.present(activityVC, animated: true, completion: nil) } else { print("file not copied so can't be shared") } } 

这是我最早的一些Swift,虽然不是很好,但是可以工作。 我有一天在我的应用程序的部署副本中使用它来debugging问题,只需发送电子邮件给自己,并打开与您的Mac上的Sqlite查看器。

实际的sqlite文件可能在共享容器中。

什么适用于我的是login商店的URL,并使用它来find它:

 print(container.persistentStoreCoordinator.persistentStores.first!.url!) 

产生类似的东西

file:///Users/developer/Library/Developer/CoreSimulator/Devices/2EAE0CD4-7899-45A3-8E83-E7D79DEEA08F/data/Containers/Data/Application/37F48A5E-7DAB-4E30-A752-F5B62826A15A/Library/Application%20Support/Events.sqlite