好吧,所以我試圖做一個應用程序,基本上是一個腳本的圖形用戶界面我無法正常工作顯示腳本的輸出在開始時我有它,所以它我應該在完成任務後完成一切,不用說不好。我現在在哪裏可以在uitextview中實時獲得輸出結果,但是隨着新信息被傳遞到圈中,導致無法讀取,我在示例中使用apt-get update腳本。我是一個新的越獄開發是的,我有我的應用程序root權限運行我唯一的問題是輸出...我的代碼是這樣的:從nstask錯誤的顯示輸出
#import "RootViewController.h"
@implementation RootViewController
@synthesize navItem;
- (void)loadView {
self.view = [[[UIView alloc] initWithFrame: [[UIScreen mainScreen] applicationFrame]] autorelease];
self.view.backgroundColor = [UIColor redColor];
navBar = [[UINavigationBar alloc] init];
navBar.frame = CGRectMake(0, 0, self.view.frame.size.width, 44);
navItem = [[[UINavigationItem alloc]
initWithTitle:@"GUI"] autorelease];
navBar.barStyle = UIBarStyleDefault;
navBar.items = [NSArray arrayWithObject:navItem];
[self.view addSubview:navBar];
NSPipe *pipe = [NSPipe pipe];
_fileHandle = [pipe fileHandleForReading];
[_fileHandle readInBackgroundAndNotify];
task = [[NSTask alloc] init];
[task setLaunchPath:@"/usr/bin/apt-get"];
[task setStandardOutput: pipe];
[task setStandardError: pipe];
NSArray *arguments;
arguments = [NSArray arrayWithObjects: @"update", nil];
[task setArguments: arguments];
[task launch];
}
-(id)init
{
[super init];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(readPipe:)
name:NSFileHandleReadCompletionNotification
object:nil];
return self;
}
-(void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
-(void)readPipe: (NSNotification *)notification
{
NSData *data;
NSString *text;
if([notification object] != _fileHandle)
return;
data = [[notification userInfo] objectForKey:NSFileHandleNotificationDataItem];
text = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding];
navItem.title = text;
titleTextField = [[UITextView alloc] initWithFrame: CGRectMake(0, 40, 320, 350)];
[titleTextField setBackgroundColor:[UIColor clearColor]];
titleTextField.text = text;
titleTextField.editable = YES;
titleTextField.scrollEnabled = YES;
titleTextField.autoresizingMask =UIViewAutoresizingFlexibleHeight;
[self.view addSubview: titleTextField];
[text release];
if(task)
[_fileHandle readInBackgroundAndNotify];
}
@end
在行中放置一個斷點:「data = [[notification userInfo] objectForKey:NSFileHandleNotificationDataItem];」 。調試器甚至在那裏? –