不能说它在模拟器中是如何工作的,但重定向标准输出并不是非常困难。假设您想将其通过管道传输到您自己的视图中:
#include <unistd.h>
stderr->_write = RedirectOutputToView;
stdout->_write = RedirectOutputToView;
并使用原型:
int RedirectOutputToView(void *inFD, const char *buffer, int size);
在XCode 6中,日志被打到这里:/Users/<username>/Library/Logs/CoreSimulator/<app guid>/system.log.用户名当然是你的系统用户名,而app guid是XCode为模拟器生成的东西.
确定应用程序guid的最简单方法是为模拟器构建应用程序并查看上次更改的目录:
~ ??? cd ~/Library/Logs/CoreSimulator
~/L/L/CoreSimulator ??? ls -latr
total 64
-rw-r--r--   1 x  staff    519 27 Aug 21:54 iOS Simulator.log
drwxr-xr-x  13 x  staff    442 27 Aug 21:54 D283605A-0BA9-43B3-AB6B-F4858BE6E45E
drwxr-xr-x  15 x  staff    510  8 Oct 03:56 425D8E41-0842-4F2D-BC22-8C3695E350EF
显然,425D8E41-0842-4F2D-BC22-8C3695E350EF是最后修改过的目录,因此现在您可以执行tail -f ~/Library/Logs/CoreSimulator/425D8E41-0842-4F2D-BC22-8C3695E350EF/system.log | grep keyword或者您可能想要对实时日志执行的任何其他操作.
| 归档时间: | 
 | 
| 查看次数: | 11300 次 | 
| 最近记录: |