私は、何かのリストをtxtに読み込むスクリプトを実行するためにNSTaskを取得しました。しかし、私の現在のコード(下記)を使用すると、NSTaskが終了する前に警告がポップアップし、空白の警告が表示されます。私はwaitUntilExit
を試しましたが、これでこのアクションを呼び出すボタンはフリーズしますが、UIはロックされません。NSTask waitUntilExit jailbreakされたiOS上でアプリをぶら下げよう
- (void) runSupported {
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];
[stask launch];
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:@"App List" message:apps delegate:self cancelButtonTitle:@"Ok!" otherButtonTitles:nil];
[supported show];
[supported release];
} else {
UIAlertView *supported = [[UIAlertView alloc] initWithTitle:@"App List" message:@"Error generating list." delegate:self cancelButtonTitle:@"Ok!" otherButtonTitles:nil];
[supported show];
[supported release];
}
}
アラートを呼び出す前にどのようにNSTaskを終了したらよいでしょうか?ありがとう。
編集:NSNotificationとコード:
-(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.");
}
}
は何plateformあなたは、iPhoneやMacをターゲットにしているNSTaskは、iOSの上で許可されていない、とUIAlertViewは、Mac上に存在しない – Guillaume
iOSのジェイルブレイク、正確には – Mitochondria