2

パラメータを使用して他のアプリケーションを開く方法を探していて、ここで非常に良い投稿を見つけましたが、開発者のマシンには、アプリケーションのテスト/ブランチ/リリース バージョンが 10 個ほどあり、/Application フォルダーには現在の安定バージョンが 1 つしかありません。 .

このコードの両方:

NSWorkspace *workspace = [NSWorkspace sharedWorkspace];

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

間違ったテスト/ブランチ/リリース バージョンを指しています。/Application フォルダー内のアプリケーションの URL、または少なくとも現在実行中のアプリケーションと同じレベルの URL を見つけるにはどうすればよいですか?

4

2 に答える 2

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.
于 2012-07-23T14:27:01.473 に答える
1

NSTaskメッセージを使用することも、他のアプリケーションへの明示的なパスを提供することsetLaunchPathもできます。launchedTaskWithLaunchPath

何かのようなもの:

NSArray *args = [NSArray arrayWithObjects:nil];
[NSTask launchedTaskWithLaunchPath:@"/Applications/My Application.app/Contents/MacOS/My Application" arguments:args];
于 2012-07-20T17:49:18.907 に答える