6

我需要在我的应用程序中添加计划。这样我的应用程序将在指定的时间和日期自动启动。我通过参考Scheduling Timed Jobs来做到这一点。我已将用于调度的 plist 文件放在/Users/username/Library/LaunchAgents. 它在非沙盒应用程序中运行良好,但在沙盒应用程序中不起作用。我无法将调度文件添加到路径/Users/username/Library/LaunchAgents。它给了我错误

Error Domain=NSCocoaErrorDomain Code=513 "“com.sample.schedule.plist” couldn’t be copied because you don’t have permission to access “LaunchAgents”." UserInfo=0x100114f10 {NSSourceFilePathErrorKey=/Users/username/Library/Developer/Xcode/DerivedData/SchedulingInSandbox-cernhnigkuqhehbndryxlekpiiiu/Build/Products/Debug/SchedulingInSandbox.app/Contents/Resources/com.sample.schedule.plist, NSUserStringVariant=(
    Copy
), NSDestinationFilePath=/Users/username/Library/LaunchAgents/com.sample.schedule.plist, NSFilePath=/Users/username/Library/Developer/Xcode/DerivedData/SchedulingInSandbox-cernhnigkuqhehbndryxlekpiiiu/Build/Products/Debug/SchedulingInSandbox.app/Contents/Resources/com.sample.schedule.plist, NSUnderlyingError=0x1001132d0 "The operation couldn’t be completed. Operation not permitted"}

我也在权利中添加了 LaunchAgents 路径。

<key>com.apple.security.temporary-exception.files.home-relative-path.read-write</key>
<array>
    <string>/Library/LaunchAgents/</string>
</array>

但我仍然无法在 LaunchAgents 目录中添加调度 plist。无论我做得正确还是有另一种方法可以在沙盒应用程序中进行调度。

编辑 1:
如果我手动创建文件夹/Library/Containers/LaunchAgents并将 plist 放在那里,我会收到此错误:

Could not open job overrides database at: /private/var/db/launchd.db/com.apple.launchd.peruser.501/overrides.plist: 1: Operation not permitted
launch_msg(): Socket is not connected
4

1 回答 1

1

尝试将您的工作清单放入

/Users/<username>/Library/Containers/<my app identifier>/Data/Library/LaunchAgents/<my app identifier>.<somename>.plist

这将是您的沙盒应用程序的数据容器。

在我的 Mac 上,我看到 FaceTime 有两个预定的作业列表,您可以将其用作示例。

于 2013-05-29T20:44:49.680 回答