我可以通過該終端命令導入XML文件的應用程序:NSTask啓動造成崩潰
打開/路徑/到/主\ app.app --args myXML.xml
這很好,沒有問題。而且我已經使用Applescript通過shell啓動這個命令,它的工作原理也一樣。然而,當嘗試使用Cocoa的NSTask啓動使用此代碼:
NSTask *task = [[NSTask alloc] init];
[task setLaunchPath:@"/usr/bin/open"];
[task setCurrentDirectoryPath:@"/Applications/MainApp/InstallData/App/"];
[task setArguments:[NSArray arrayWithObjects:[(NSURL *)foundApplicationURL path], @"--args", @"ImportP.xml", nil]];
[task launch];
應用程序將啓動初始屏幕,那麼無論是下一個按鈕被點擊或試圖關閉窗口時的時候崩潰。
NSAppleScript *script = [[NSAppleScript alloc] initWithSource:@"tell application \"Terminal\" do script \"open /Applications/MainApp/InstallData/App/Main\\\\ App.app\" end tell"];
NSDictionary *errorInfo;
[script executeAndReturnError:&errorInfo];
這將啓動程序,它會崩潰,以及和我在我的Xcode的調試窗口收到此錯誤:使用NSAppleScript這個我用盡
12011-01-04 17:41:28.296 LaunchAppFile[4453:a0f]
Error loading /Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types: dlopen(/Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types, 262): no suitable image found.
Did find: /Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types: no matching architecture in universal wrapper
LaunchAppFile: OpenScripting.framework - scripting addition "/Library/ScriptingAdditions/Adobe Unit Types.osax" declares no loadable handlers.
因此,與研究,我想出了這個:
NSAppleScript *script = [[NSAppleScript alloc] initWithSource:@"do shell script \"arch -i386 osascript /Applications/MainApp/InstallData/App/test.scpt\""];
NSDictionary *errorInfo;
[script executeAndReturnError:&errorInfo];
但是這會導致與最後一個命令相同的結果。 關於造成這次事故的原因有什麼想法?
果然。 Adobe正在吐出被卡住/被解析的東西。 我不是C開發人員,但這是我被告知發生的事情。 – tripskeet 2011-04-07 21:44:59