有权在macOS上自动打开目录的权利

问题描述 投票:0回答:1

我用电子程序构建了一个将文本保存到用户所选目录中文件的应用程序。在应用启动时,用户选择应存储其数据的目录。我用electron-settings保存该目录,并在下次启动应用程序时再次自动加载该目录。

在本地,一切正常,但是我很难将它打包为macOS .app文件并且在签名后才能工作。

当前我的权利看起来像这样

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
  <dict>
    <key>com.apple.security.app-sandbox</key>
    <true/>
    <key>com.apple.security.application-groups</key>
    <string>APPLE_GROUP_STRING</string>
    <key>com.apple.security.files.user-selected.read-write</key>
    <true/>
    <key>com.apple.security.files.bookmarks.document-scope</key>
    <true/>
    <key>com.apple.security.files.bookmarks.app-scope</key>
    <true/>
  </dict>
</plist>

[当我选择目录时,一切正常,但是当我关闭应用程序,然后尝试将文件读/写到同一目录时,出现“权限被拒绝”错误。 (在再次手动选择目录后,它可以按预期工作)

我需要设置什么权限才能在启动时访问目录?还有其他解决方法吗?也许有一个按钮可以直接打开目录,而没有通常的文件选择对话框?

我已经尝试使用

<key>com.apple.security.temporary-exception.files.absolute-path.read-write</key>
<array>
    <string>/</string>
</array>

但出于非常明显的原因,Apple验证拒绝了对/拥有读/写访问权限的应用程序

electron electron-builder mac-app-store appstore-sandbox entitlements
1个回答
0
投票

[尝试不仅使用electron-settings保存目录,还尝试将其另存为Security Scoped Bookmark。重新启动后,您可以再次访问此目录。

© www.soinside.com 2019 - 2024. All rights reserved.