使用目标文件启动应用程序

ort*_*t11 2 macos objective-c launching-application

使用NSWorkSpace launchApplication,如果使用应用程序文件,一切都很好,但是如果想要使用像untitled.rtf这样的目标文件启动应用程序会怎么样?

[[NSWorkspace sharedWorkspace] launchApplication:selection]
Run Code Online (Sandbox Code Playgroud)

Ber*_*ter 9

使用-[NSWorkspace openFile:WithApplication:]如下:

[[NSWorkspace sharedWorkspace] openFile:@"/Myfiles/untitled.rtf"
    withApplication:@"TextEdit"];
Run Code Online (Sandbox Code Playgroud)

或者,如果只想使用该文件的默认应用程序打开文件,请使用-[NSWorkspace openFile:]如下:

[[NSWorkspace sharedWorkspace] openFile:@"/Myfiles/untitled.rtf"];
Run Code Online (Sandbox Code Playgroud)

请务必查看NSWorkspace文档以获取详细信息和其他相关方法.