The "Open" menu item of my app is gray - How can I open files from within my app?

I've completed a simple app that plays 3D video. Now, I'm trying to make it open files from the menu, as well as using the Cmd-O keyboard shortcut.

But the "Open" menu item in the "File" menu is gray - I don't know exactly what this means, but it seems that the current form of the app doesn't support openning files.

I've had a func application(_ application: NSApplication, openFile filename: String) -> Bool function in my app delegate, I've had a CFBundleDocumentTypes with an entry of the MIME type of "video/mp4".

What am I doing wrong?

Answered by DannyNiu-NJF in 719516022

The app delegate callback is only used with NSDocument-based file-opening method, which requires configuring appropriate file types supported by the app in app's "Info.plist".

We can instead rely on NSOpenPanel for a customized file openning experience - write an @IBAction callback to be invoked when the open command is issued (from keyboard shortcut or app menu), and instantiate an NSOpenPanel to open the file.

Accepted Answer

The app delegate callback is only used with NSDocument-based file-opening method, which requires configuring appropriate file types supported by the app in app's "Info.plist".

We can instead rely on NSOpenPanel for a customized file openning experience - write an @IBAction callback to be invoked when the open command is issued (from keyboard shortcut or app menu), and instantiate an NSOpenPanel to open the file.

The "Open" menu item of my app is gray - How can I open files from within my app?
 
 
Q