如何创建和访问共享应用程序组文档目录?

how can I create and access share app group document directory?

我正在使用自定义键盘扩展,然后从服务器下载键盘主题并保存到应用文档目录中,但应用文档目录无法在自定义键盘扩展中访问,因此需要共享应用组目录。我该怎么做,请帮助我。

现在我正在尝试这个,但它不起作用。

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)
                }

已解决

  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)!)!