tayloraswift / swift-png

decode, inspect, edit, and encode png images in pure swift

Home Page:https://swiftinit.org/docs/swift-png

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

fails to load png file in MacOS sandboxed environment, even if App has all the right flags set

S1D1T1 opened this issue · comments

sandboxed MacOS App cannot open a User-Selected PNG file, even when the app has set all the right bits. (Tested with reading other files with code not in swift-png.)

Reading the same file from within the App's sandbox (~/Library/Containers/my-app/) succeeds. According to this stackoverflow post, it's because the library accesses the file via a simple string path, rather than the blessed URL returned by the file importer dialog.

https://stackoverflow.com/questions/74534788/macos-swift-app-on-xcode-14-1-cannot-read-user-selected-file

request that swift-png entry points accept file URLS to enable its use in sandboxed MacOS apps. thank you!

(am brand new to git, please interpret protocol errors as naïveté, not belligerence, thanks)

update: the OS does indeed allow opening files by string path while sandboxed, if the App first blesses the url with:
_=url.startAccessingSecurityScopedResource()
and then passing the string path to decompress. It might still make a nice optional interface to allow passing a file URL, and have swift-png take care to that detail.