如何下载sqlite存储文件的iMessage扩展到MacBook [英] How to download sqlite store file of iMessage extension to MacBook
问题描述
我们正在开发一个iMessage扩展。它成功使用Core Data。我们需要评估store.sqlite文件,但找不到它。
我们尝试这样找到:
- 在Xcode:Window - >设备
- 在
已安装的应用
/ li>
-
下载容器...
但是容器为空:
更新:
file:/// var / mobile / Containers / Data / PluginKitPlugin / 9C15B67C- 8917-4A24-9FB0-BD119C43B3C4 / Library / Application%20Support / Model.sqlite
现在我们试图将模型复制到文档
文件夹,以便能够通过Xcode下载到我们的MacBook(见上文)。
到`Documents:
NSSearchPathForDirectoriesInDomains(.documentDirectory,.userDomainMask,true)[0]
又在 / var / mobile / Containers /
:
file:/// var / mobile / Containers / Data / PluginKitPlugin / D0BBD375-A8B7-43DD-8486-1909965CAEB0 / Documents
<如何从共享容器下载Model.sqlite文件到我们的MacBook? class =h2_lin>解决方案最好的办法是使用邮件共享操作写出口商。在我的一个应用程序中,我允许用户通过电子邮件发送sqlite文件的副本导出所有数据。
func exportAllDataSqlite (){
let documentsUrl = FileManager.default.urls(for:.documentDirectory,in:.userDomainMask).first!
var newFilePath:URL!
var mutablePathComponents = [String]()
var sqliteFileCopied = false
do {
让directoryContents = try FileManager.default.contentsOfDirectory(at:documentsUrl,includingPropertiesForKeys: nil,选项:FileManager.DirectoryEnumerationOptions())
for f在directoryContents {
let pathComponents = f.pathComponents
如果pathComponents.last ==XXXXW无论你的文件被创建的persisten store.sqliteXXXXX{
//创建带有过期文件名的文件的副本
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] =活动App \(dateString).sqlite
newFilePath = NSURL.fileURL(withPathComponents:mutablePathComponents)
do {
try FileManager.default.copyItem(at:f,to:newFilePath!)
sqliteFileCopied = true
print(复制sqlite文件)
} catch让错误为NSError {
print(error.localizedDescription)
}
}
}
} catch let错误为NSError {
print (error.localizedDescription)
}
如果sqliteFileCopied == true {
//共享
让activityItem:URL = newFilePath!
let objectsToShare = [activityItem]
让activityVC = UIActivityViewController(activityItems:objectsToShare,applicationActivities:nil)
activityVC.completionWithItemsHandler = {activity,success,items,错误
do {
try FileManager.default.removeItem(at:newFilePath!)
print(已删除的文件:\(newFilePath!))
} catch let错误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(文件未复制,因此无法共享)
}
}
这是我最早的一个Swift,所以不是很好,但它的工作原理。我使用它的另一天在我的应用程序的部署副本调试一个问题,只是电子邮件给自己和打开与您的mac上的Sqlite查看器。
We are developing an iMessage extension. It uses Core Data successfully. We need to evaluate the store.sqlite file, but can not find it.
We try to find it like this:
- In Xcode: Window -> Devices
- In
Installed Apps
, select our extension
Download Container ...
But the container is empty:
Update:
Thanks to @Mundi's answer we found out how to get the models URL:
file:///var/mobile/Containers/Data/PluginKitPlugin/9C15B67C-8917-4A24-9FB0-BD119C43B3C4/Library/Application%20Support/Model.sqlite
Now we are trying to copy the Model to the Documents
folder, to be able to download it later to our MacBook via Xcode (see above).
Unfortunately the path to `Documents:
NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0]
is again in /var/mobile/Containers/
:
file:///var/mobile/Containers/Data/PluginKitPlugin/D0BBD375-A8B7-43DD-8486-1909965CAEB0/Documents
How can we download the Model.sqlite file from a shared container to our MacBook?
解决方案 Your best bet with this is to write an exporter using the mail share action. In one of my apps I allow the user to export all of the data by emailing a copy of the sqlite file.
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")
}
}
It's some of my earliest Swift so not great but it works. I used it the other day in a deployed copy of my app to debug an issue, just email to yourself and open with an Sqlite viewer on your mac.
这篇关于如何下载sqlite存储文件的iMessage扩展到MacBook的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!