Skip to content

NSApplicationDelegate

Ken Harris edited this page Jun 18, 2020 · 2 revisions

If you want to accept drops on your app's dock icon, you need to implement either:

application(_ sender: NSApplication, openFiles filenames: [String])  // call sender.reply(toOpenOrPrint: .success)
application(_ sender: NSApplication, openFile filename: String) -> Bool  // return true = success

If you implement both, it always takes the openFiles variant, even for single file drops. There doesn't seem to be any advantage to either one. Note that it may call either one multiple times, even for a single drop.

  • UPDATE: In fact, openFile is strictly better, because you can report success/failure for each individual file. There doesn't seem to be any way for openFiles to report anything except success/failure for the whole bunch at once.

macOS bug?: if the user drops a file of type "public.archive" with the "com.apple.quarantine" flag set, the OS will not inform your app of any filenames past the quarantined archive. This occurs regardless of which method you implement. Observed in every version of macOS tested so far (10.11 through 10.14). Note that the quarantine flag doesn't prevent you from opening the file! You just won't get told about any more files.

Clone this wiki locally