Comparing different 'the launching Cocoa app with parameters' methods

前端 未结 2 1543
攒了一身酷
攒了一身酷 2021-01-03 07:11

I found there are at least three ways to launch an app with Mac OS X from an application.

  1. NSTask. I can give parameters, but it seems that it\'s not for an Coc
2条回答
  •  再見小時候
    2021-01-03 07:33

    In 10.6 and later, NSWorkspace has a method launchApplicationAtURL:options:configuration:error: that can be used to pass arguments to the app.

    There are also Launch Services functions such as LSOpenItemsWithRole.

    You could also send an AppleEvent to the Finder asking it to open something.

    EDIT TO ADD: "best" is subjective, but I'd say if you can use NSWorkspace, use it. If you can't, e.g., you need to pass command-line parameters and you need to support Leopard, then use Launch Services.

提交回复
热议问题