【问题标题】:Jailbroken iOS: NSTaskDidTerminateNotification fails to launch selector越狱 iOS:NSTaskDidTerminateNotification 无法启动选择器
【发布时间】:2011-03-24 09:44:16
【问题描述】:

我好像遇到了和这里一样的问题:NSTask waitUntilExit hanging app on jailbroken iOS

这是我通过 NSNotification 获得的信息(如上),但没有出现 taskEnded: 警报。该脚本肯定已运行,正如我在调试器中看到的那样。

-(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."); 
    }
}

【问题讨论】:

    标签: iphone jailbreak nstask nsnotification


    【解决方案1】:

    试试

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-03-26
      • 1970-01-01
      • 1970-01-01
      • 2013-05-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多