我需要在我的应用中添加日程安排。这样我的应用程序将在指定的时间和日期自动启动。我是通过引用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目录中添加scheculing 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
答案 0 :(得分:1)
尝试将你的工作放入
/Users/<username>/Library/Containers/<my app identifier>/Data/Library/LaunchAgents/<my app identifier>.<somename>.plist
这将是您沙盒应用的数据容器。
在我的Mac上查看我看到FaceTime有两个预定的作业plist,你可以用它作为例子。