使用的iOS重定向的方式,将原本输出到Xcode内的文本全部绑定到UITextView上。原来的地址不记得了。
- (void)redirectNotificationHandle:(NSNotification *)nf{
NSData *data = [[nf userInfo] objectForKey:NSFileHandleNotificationDataItem];
NSString *str = [[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding] autorelease];
self.logTextView.text = [NSString stringWithFormat:@"%@\n%@",self.logTextView.text, str];
NSRange range;
range.location = [self.logTextView.text length] - 1;
range.length = 0;
[self.logTextView scrollRangeToVisible:range];
[[nf object] readInBackgroundAndNotify];
}
- (void)redirectSTD:(int )fd{
NSPipe * pipe = [NSPipe pipe] ;
NSFileHandle *pipeReadHandle = [pipe fileHandleForReading] ;
dup2([[pipe fileHandleForWriting] fileDescriptor], fd) ;
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(redirectNotificationHandle:)
name:NSFileHandleReadCompletionNotification
object:pipeReadHandle] ;
[pipeReadHandle readInBackgroundAndNotify];
}
- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOption{
[self redirectSTD:STDOUT_FILENO];
[self redirectSTD:STDERR_FILENO];
//YOUR CODE HERE...
}
如果想要去掉该功能将最下方的方法屏蔽掉就好了。