问题
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