gpt4 book ai didi

swift - 将 TPK 文件从 AppGroup 容器复制到文档

转载 作者:行者123 更新时间:2023-11-30 12:59:43 24 4
gpt4 key购买 nike

我有一个文件存在于 AppGroup 共享容器中,我想知道是否可以将该文件从共享容器复制到应用程序包中。

我获取的文件路径如下:

let filePath = NSFileManager.defaultManager().containerURLForSecurityApplicationGroupIdentifier("group.com.sharedBasemap")!.URLByAppendingPathComponent("localLayer.tpk")!.path

我尝试执行此操作的原因是,ArcGIS SDK 似乎无法识别应用程序组中的 TPK 文件,因此我想知道如果我将其复制到应用程序包中,它是否会识别它。

编辑:根据 Leo 的评论,您似乎无法复制到 bundle ,因此我尝试复制到应用程序支持文件夹。
现在这是我的代码,我看到“文件存在”消息但随后它显示 Oops 消息,表明它无法移动文件:

let filePath = NSFileManager.defaultManager().containerURLForSecurityApplicationGroupIdentifier("group.com.sharedBasemap")!.URLByAppendingPathComponent("localLayer.tpk")!.path!
let appSupportFolder = String(NSFileManager.defaultManager().URLsForDirectory(.ApplicationSupportDirectory, inDomains: .UserDomainMask)[0]) + "localLayer.tpk"
let fileManager = NSFileManager.defaultManager()

if NSFileManager.defaultManager().fileExistsAtPath(filePath){
print("File exists at \(filePath)")
do {
try fileManager.copyItemAtPath(filePath, toPath: appSupportFolder)
}
catch let error as NSError {
print("Ooops! Something went wrong: \(error)")
}
} else {
print("File does not exist")
}

编辑2:我再次修改了代码,将TPK文件移动到文档目录中。
我相信该部分正在工作,但在尝试将TPK文件加载到ArcGIS时收到一条错误消息。< br/>此时,我认为该问题与 ArcGIS SDK 有关,并且它不支持从应用程序包之外的任何位置加载 TPK 文件。

let destPath = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true).first!
let fullDestPath = NSURL(fileURLWithPath: destPath).URLByAppendingPathComponent("localLayer.tpk")
let fullDestPathString = fullDestPath!.path!

最佳答案

我很确定 appSupportFolder 默认情况下不存在 - 除非需要,否则没有人创建它 - 尝试首先验证并在需要时创建它

pseudocode if(!fileExists(supportFolder)) { createDirectory(supportFolder) }

关于swift - 将 TPK 文件从 AppGroup 容器复制到文档,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39986363/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com