2011-03-24 114 views
1

我好像這裏同樣的問題:NSTask waitUntilExit hanging app on jailbroken iOS越獄的iOS:NSTaskDidTerminateNotification無法啓動選擇

下面是我通過NSNotification了(如上),尚taskEnded:警報(S)不來向上。該腳本確實運行,因爲我可以在調試器中看到它。

-(IBAction) supported { 
    stask = [[NSTask alloc] init]; 
    [stask setLaunchPath:@"/bin/bash"]; 
    NSString *script; 
    script = [[[NSBundle mainBundle] bundlePath] stringByAppendingString:@"/apps.sh"]; 
    NSArray *sargs = [NSArray arrayWithObjects:script, @"-txt", nil]; 
    [stask setArguments: sargs]; 
    [[NSNotificationCenter defaultCenter] addObserver: self 
              selector: @selector(taskEnded:) 
               name: NSTaskDidTerminateNotification 
               object: nil]; 
    [stask launch]; 
} 

- (void)taskEnded:(NSNotification *)notification { 
    if (stask == [[notification object] terminationStatus]) { 
     NSString *apps; 
     apps = [NSString stringWithContentsOfFile:@"/var/mobile/supported.txt" encoding:NSUTF8StringEncoding error:nil]; 
     NSFileManager *fm = [NSFileManager defaultManager]; 
     if ([fm fileExistsAtPath:apps]) { 
      UIAlertView *supported = [[UIAlertView alloc] initWithTitle:@"Apps" message:apps delegate:self cancelButtonTitle:@"Ok!" otherButtonTitles:nil]; 
      [supported show]; 
      [supported release]; 
     } else { 
      UIAlertView *supported = [[UIAlertView alloc] initWithTitle:@"Apps" message:@"Error generating list." delegate:self cancelButtonTitle:@"Ok!" otherButtonTitles:nil]; 
      [supported show]; 
      [supported release]; 
     } 
    } else { 
     NSLog(@"Task failed."); 
    } 
} 

回答

0

嘗試

[[NSNotificationCenter defaultCenter] addObserver: self 
              selector: @selector(taskEnded:) 
               name: NSTaskDidTerminateNotification 
               object: stask];