NSLog() 回调后不输出
我在一个我知道正在被调用的方法中有一个 NSLog 调用(我已经设置了一个断点)。但该方法中没有输出,或者在该方法之后根本没有输出。当应用程序启动时,我的 NSLog 语句工作正常。我想知道这是否是某种线程问题。
NSLog 在 taskDidTerminate 方法中停止,该方法是来自 NSTask 的回调:
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(taskDidTerminate:)
name:NSTaskDidTerminateNotification
object:localTask];
有什么想法吗?
编辑:taskDidTerminate
- (void) taskDidTerminate: (NSNotification *) notification
{
NSLog(@"TaskDid Terminate");
[task.delegate taskCompleted:task];
}
I've got an NSLog invocation in a method that I know is getting called (I've set a breakpoint). But there's not output in that method, or at all after that method. When the app starts up, my NSLog statements are working fine. I'm wondering if this is some sort of threading issue.
NSLog stops in the taskDidTerminate method, which is a callback from an NSTask:
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(taskDidTerminate:)
name:NSTaskDidTerminateNotification
object:localTask];
Any ideas?
Edit: taskDidTerminate
- (void) taskDidTerminate: (NSNotification *) notification
{
NSLog(@"TaskDid Terminate");
[task.delegate taskCompleted:task];
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
事实证明,当您使用 /bin/bash -c (任务) (命令) 执行任务时,XCode 看起来并不喜欢它。我现在已将其更改为直接执行任务,现在我的 NSLog() 语句正在运行。
请参阅此处以获取参考。
As it turns out, it doesn't look like XCode likes it when you execute a task using /bin/bash -c (task) (commands). I've now changed it to directly execute the task, and now my NSLog() statements are working.
See here for a reference.
添加
[task setStandardInput:[NSPipe pipeline]];
可能会恢复您的日志,如 CocoaDev:NSTask。Adding
[task setStandardInput:[NSPipe pipe]];
may bring your logs back as stated on CocoaDev: NSTask.