我需要在我的应用程序中添加调度功能,以便我的应用程序可以在指定的时间和日期自动启动。我通过参考计划定时作业来完成这个功能。我已经将用于调度的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>
但我仍然无法将调度plist添加到LaunchAgents目录中。我是否做得正确或者有其他方法在沙盒应用程序中进行调度。
编辑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