我看到了一些关于如何在后台保持NSTask运行的好信息,尽管那不完全是我想做的。我想做的是定期在后台运行NSTask(例如每30秒),然后结束它;这可能是我想要做的一个示例:
NSTask *theTask = [ [ NSTask alloc ] init ];
NSPipe *taskPipe = [ [ NSPipe alloc ] init ];
[ theTask setStandardError:taskPipe ];
[ theTask setStandardOutput:taskPipe ];
[ theTask setLaunchPath:@"/bin/ls" ];
[ theTask setArguments:[ NSArray arrayWithObject:@"-l" ] ];
[ theTask launch ];
// Wait 30 seconds, then repeat the task