0
我正在啓動帶有駐留在我的objective-c代碼中的Applescript的JAR。無法在目標中產生新線程 - C
我想在新線程(NSThread)中執行此操作。
請注意:我已經使用過GCD,但它並不能幫助我,因爲即使併發隊列對主線程有依賴關係 。
-(void) launchJar{
NSAppleScript *script = [[NSAppleScript alloc] initWithSource:scriptToLaunch];
[script executeAndReturnError:nil];
NSLog(@"hitting this point");
}
int main(int argc, char *argv[]) {
@autoreleasepool {
MCMCustomURLSchemeHandler *mcmCustomURLHandler = [[MCMCustomURLSchemeHandler alloc] init];
[NSThread detachNewThreadWithBlock:@selector(launchJar) toTarget:[JARLauncher class] withObject:nil];
return NSApplicationMain(argc, argv);
}
}
我遵循你的建議,並得到它運行。我在發佈launchJar方法的位置也遇到了問題。 解決這個問題讓我意識到另一個問題:http://stackoverflow.com/questions/40904677/how-do-i-ensure-that-i-close-my-app-only-when-all-the-threads -have-finished-exec 你可以看看嗎? –