我正在使用自定义键盘扩展名,然后从服务器下载键盘主题并保存到应用程序文档目录中,但是应用程序文档目录无法在自定义键盘扩展名中访问,因此需要共享应用程序组目录。我该怎么办请帮助我。
现在我正在尝试这种方法,但是它不起作用。
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)
}
答案 0 :(得分:0)
已解决
let fileManager = FileManager.default
let url = fileManager.containerURL(forSecurityApplicationGroupIdentifier: "group.companyname.appname")?.appendingPathComponent("logo.png")
// store image in group container
if !fileManager.fileExists(atPath: url!.path) {
let image = UIImage(data: data)
let imageData : Data = UIImagePNGRepresentation(image!) as! Data
fileManager.createFile(atPath: url!.path as String, contents: imageData, attributes: nil)
}
//ACCESS THIS or get store image
let Image1 = UIImage(contentsOfFile: (url?.path)!)!