Objective C launchApplicationAtUrl 参数不起作用

Objective C launchApplicationAtUrl arguments not working

我想通过 launchApplicationAtURL 使用一些参数打开 Photoshop 应用程序。 Photoshop 已打开,但我在参数列表中指定的图像未打开。

NSWorkspace *workspace = [NSWorkspace sharedWorkspace];
NSString *urlString = [NSString stringWithUTF8String:imageEditorPath.GetPlatformString().c_str()];
NSURL *url = [[NSURL alloc] initFileURLWithPath:urlString];
//Handle url==nil
NSError *error = nil;
NSArray *arguments = [NSArray     arrayWithObjects:@"/Users/admin/q/177381.png", nil];
[workspace launchApplicationAtURL:url options:0 configuration: [NSDictionary dictionaryWithObject:arguments forKey:NSWorkspaceLaunchConfigurationArguments] error:&error];

中日韩回答正确: [[NSWorkspace sharedWorkspace] openURLs:fileURLs withApplicationAtURL:appURL options:0 configuration:0 错误:&err];其中 fileURLs 是要打开的文件数组,appURL 指向应用程序。 – 中日韩

CJK - 请作为答复发送。

参考我上面的评论,可以使用 NSWorkspace 方法 openURLs:withApplicationAtURL:options:configuration:error:. If you don't need to send any arguments to the application, or set environment variables for the app, then one can simply pass NULL to the configuration: parameter. Likewise, there are a multitude of NSWorkspaceLaunchOptions available 在一个应用程序中打开多个文件,但如果需要 none 个,可以通过 0options: 参数:

NSURL *appURL = [NSURL fileURLWithPath:@"file:///path/to/application.app"];
NSArray *fileURLs = [NSArray arrayWithObjects:[NSURL fileURLWithPath:@"file:///path/to/file1"],
                                              [NSURL fileURLWithPath:@"file:///path/to/file2"],
                                              nil];
NSError *err = nil;
BOOL success = [[NSWorkspace sharedWorkspace] openURLs:fileURLs withApplicationAtURL:appURL 
                                              options:0 configuration:NULL error:&err];