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

两盒软妹~` 提交于 2019-12-20 07:40:46

问题


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

回答1:


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


来源:https://stackoverflow.com/questions/55547930/how-can-i-create-and-access-share-app-group-document-directory

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!