swiftcustom-keyboardios-app-groupdocument-directory

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


i am using custom keyboard extension then download keyboard theme from server and save in to app document directory but app document directory can not access in custom keyboard extension so, required to share app group directory. how can i do please help me.

Now i am trying this but its not working.

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

Solution

  • Solved

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