2012-07-20 99 views
1

我正在尋找一種方法來打開我的其他應用程序的參數,並找到very good post here,但在我的開發人員機器上,我有10個測試/佈告/版本的應用程序/ Application文件夾中的一個當前穩定版本。首先在/應用程序文件夾中搜索應用程序

兩個驗證碼:

NSWorkspace *workspace = [NSWorkspace sharedWorkspace]; 

NSURL *url = [NSURL fileURLWithPath:[workspace fullPathForApplication:@"My Application"]]; 
NSURL *url = [workspace URLForApplicationWithBundleIdentifier:@"it.my_company.my_application"]; 

指向錯誤的測試/分公司/發行版本。如何在/ Application文件夾中找到我的應用程序的URL,或者至少找到與我當前運行的應用程序相同級別的URL?

回答

1

這就是我心中已經出來了使用方法:

NSWorkspace *workspace = [NSWorkspace sharedWorkspace]; 

NSString *appPath = [[[NSBundle mainBundle] bundlePath] stringByDeletingLastPathComponent]; 
appPath = [appPath stringByAppendingPathComponent:@"MyApp.app"]; 

if (not [[NSFileManager defaultManager] fileExistsAtPath:appPath]) 
    appPath = @"/Applications/MyApp.app"; 

if (not [[NSFileManager defaultManager] fileExistsAtPath:appPath]) 
    appPath = [workspace fullPathForApplication:@"MyApp"]; 

if (not [[NSFileManager defaultManager] fileExistsAtPath:appPath]) { 
    return NO; 
} 
else { 
    // found it in some place, now can launch. 
1

您可以使用NSTask消息:setLaunchPathlaunchedTaskWithLaunchPath提供明確的路徑到你的其它應用。

喜歡的東西:

NSArray *args = [NSArray arrayWithObjects:nil]; 
[NSTask launchedTaskWithLaunchPath:@"/Applications/My Application.app/Contents/MacOS/My Application" arguments:args]; 
+0

心中已經考慮過,但它是一個手動寫路徑...我一直在尋找改變路徑搜索順序。 – Shebuka 2012-07-23 14:24:04

相關問題