【发布时间】:2019-08-28 02:20:51
【问题描述】:
我正在使用自定义键盘扩展,然后从服务器下载键盘主题并保存到应用程序文档目录,但应用程序文档目录无法在自定义键盘扩展程序中访问,因此需要共享应用程序组目录。我该怎么办,请帮帮我。
现在我正在尝试这个,但它不起作用。
let fileManager = FileManager.default
if let directory = fileManager.containerURL(forSecurityApplicationGroupIdentifier: "group.companyname.appname") {
//let newDirectory = directory.appendingPathComponent(dataPath)
newDirectory = directory.appendingPathComponent("MyDirectory")
try? fileManager.createDirectory(at: newDirectory, withIntermediateDirectories: false, attributes: nil)
print(newDirectory.path)
}
【问题讨论】:
-
您是否在两个目标上都启用了应用组?
-
是的,已经这样做了
-
使用上面创建的目录而不是app文档目录来保存文件。
-
我用于在扩展中获取数据,但它不像下面那样工作
-
let fileManager = FileManager.default if let directory = fileManager.containerURL(forSecurityApplicationGroupIdentifier: "group.anishmodan.fontapp") { print(directory.path) let pathUrl = directory.appendingPathComponent("Test.jpg ") print(pathUrl.path as Any) let Image1 = UIImage(contentsOfFile: pathUrl.path)! //在imageview上设置后}
标签: swift custom-keyboard ios-app-group document-directory