简体   繁体   中英

Finder Sync Extension unable to read/write file from Desktop

I'm trying to read a file from Desktop using Finder Sync Extension context menu, but it's not working as expected. I have added all required sandbox settings and other file locations like Downloads are working fine, but Desktop files are not.

Are there any other settings related to Desktop to read/write files?

该问题已通过在授权密钥中明确添加桌面位置的绝对路径来解决。

Is the Desktop location included in directoryURLs property of the FinderSync controller?

/*
For each directory present in directoryURLs, the extension can receive -beginObservingDirectoryAtURL: and -endObservingDirectoryAtURL: for that directory and for any directories inside. Always set directoryURLs when the extension starts; if there are no directories to be watched, pass the empty set.
*/

open var directoryURLs: Set<URL>!

You should determine if the issue is due to Sandbox access violation, or an access-level misuse of the FinderSync extension API itself:

let rootDirectory = URL(fileURLWithPath: "/")
FIFinderSyncController.default().directoryURLs = [rootDirectory]

The issue was resolve by poster, but here's an example: (this is based on an answer from: https://stackoverflow.com/a/58389937/3276518 )

Mainly:

Access that can be set directly from Xcode
com.apple.security.files.downloads.read-only and com.apple.security.files.user-selected.read-only

Absolute path:
com.apple.security.temporary-exception.files.absolute-path.read-only

Home relative path:
com.apple.security.temporary-exception.files.home-relative-path.read-only

<plist version="1.0">
<dict>
    <key>com.apple.security.app-sandbox</key>
    <true/>
    <key>com.apple.security.files.downloads.read-only</key>
    <true/>
    <key>com.apple.security.files.user-selected.read-only</key>
    <true/>
    <key>com.apple.security.temporary-exception.files.absolute-path.read-only</key>
    <array>
        <string>/Users/<username>/Music/access.txt</string>
    </array>
    <key>com.apple.security.temporary-exception.files.home-relative-path.read-only</key>
    <array>
        <string>/Desktop/access.txt</string>
    </array>
</dict>
</plist>

The Documents folder is not the main folder of the user. In Sandbox context, there's a Documents folder in the container.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM