
要在App和Extension之间共享CoreDatas持久性store.sqlite,我们正在使用共享的“Apple App Group”目录,该目录运行正常.
现在我们出于调试原因而无法找到该目录. Apps容器目录是完全空的,这是有道理的.但是如何下载我们的数据库?我们是否必须以某种方式将其以编程方式复制到可到达的地方?
把它们加起来:
>我们已经使用CoreData将model.sqlite存储在我们的共享目录中.
>一切都在运转.
>我们要归档的是将数据库下载到我们的计算机.
如果没有共享目录,我们只需使用Xcode-> Devices从设备下载App容器即可.但是当我们使用共享目录时,.sqlite数据库不在容器中.
题:
我们怎样才能将.sqlite数据库从设备下载到我们的计算机上?
在Swift 4.x中:
let sharedContainerURL :URL? = fileManager.default.containerURL(forSecurityApplicationGroupIDentifIEr: "group.etc.etc")// replace "group.etc.etc" above with your App Group's IDentifIErNSLog("sharedContainerURL = \(String(describing: sharedContainerURL))")if let sourceURL :URL = sharedContainerURL?.appendingPathComponent("store.sqlite") { if let destinationURL :URL = fileManager().urls(for: .documentDirectory,in: .userDomainMask).first?.appendingPathComponent("copyOfStore.sqlite") { try! fileManager().copyItem(at: sourceURL,to: destinationURL) }} 在旧版本的Swift(可能是Swift 2.x)中:
let sharedContainerURL :NSURL? = NSfileManager.defaultManager().containerURLForSecurityApplicationGroupIDentifIEr("group.etc.etc") // replace "group.etc.etc" with your App Group's IDentifIErNSLog("sharedContainerURL = \(sharedContainerURL)")if let sourceURL :NSURL = sharedContainerURL?.URLByAppendingPathComponent("store.sqlite"){ if let destinationURL :NSURL = NSfileManager().URLsForDirectory(.documentDirectory,inDomains: .UserDomainMask)[0].URLByAppendingPathComponent("copyOfStore.sqlite") { try! NSfileManager().copyItemAtURL(sourceURL,toURL: destinationURL) }} 像上面这样的东西会从应用程序组的共享容器中获取一个文件到应用程序的documents目录.从那里,你可以使用Xcode>窗口>将设备送到您的计算机的设备.
在Info.pList文件中将UIfileSharingEnabled设置为YES后,您还可以使用iTunes文件共享从应用程序的documents目录中检索文件,但请记住,这也会将目录的内容公开给用户.不过,应该可以用于开发/调试目的.
总结以上是内存溢出为你收集整理的ios – 如何查找Apple App Group共享目录全部内容,希望文章能够帮你解决ios – 如何查找Apple App Group共享目录所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)