0

I use the following code to write a png file to the App Group folder to share between my share extention and App , and i found that the write to file can be succeed (i can find the file in my terminal) , but after the writing , I use the contentsOfDirectory to get the contents of App Group Folder ,it will failed and throw

Error Domain=NSCocoaErrorDomain Code=260 "The folder “435D6129-B964-46A4-A066-47133EFF832D” doesn’t exist." UserInfo={NSUserStringVariant=(
    Folder 

enter image description here

because I can write to the App group , so I think the configuration of App Group is OK , but why I can't use contentsOfDirectory to get the contents of the App group directory?

Itay Brenner
  • 800
  • 6
  • 19
ximmyxiao
  • 2,622
  • 3
  • 20
  • 35

1 Answers1

3

Using URL.absoluteString will return an invalid path because it contains the file scheme file://.

You should use URL.path, in your case it would be:

let contents = try FileManager.default.contentsOfDirectory(atPath: groupURL.path)
Itay Brenner
  • 800
  • 6
  • 19
  • @ximmyxiao or simply use the `func contentsOfDirectory(at url: URL, includingPropertiesForKey:, options:)` method in your case: `FileManager.default.contentsOfDirectory(at: groupURL)` – Leo Dabus Sep 25 '20 at 05:57