Replacing the Preferences item in a menu bar

Per default the menu bar on iPad includes an application menu named after your app which includes a Preferences action. That one opens the Settings app to your app settings page.

I do not really populate that with options and instead have my own settings UI accessible in my app using toolbar items.

What's the best approach to handle this with the menu bar?

I've tried replacing the default Preferences item but that only works if I do not use its shortcut, which I would like to preserve.

Another solution would be to append another Settings item for my UI, which would look weird and confusing, but seems to be the recommended way from the HIG.

Reserve the YourAppName > Settings menu item for opening your app’s page in iPadOS Settings. If your app includes its own internal preferences area, link to it with a separate menu item beneath Settings in the same group. Place any other custom app-wide configuration options in this section as well.

I take it there is no way to replace it then?

Answered by DTS Engineer in 851545022

I'll defer to the HIG for best practices. You cannot replace the default Preferences or Settings menu item in the macOS or iPadOS menu bar that's automatically generated for your app. That said, you can supplement that with your own app-specific needs using the commands(content:) modifier.

Checkout Building and customizing the menu bar with SwiftUI for guidance on native menu bars.

Accepted Answer

I'll defer to the HIG for best practices. You cannot replace the default Preferences or Settings menu item in the macOS or iPadOS menu bar that's automatically generated for your app. That said, you can supplement that with your own app-specific needs using the commands(content:) modifier.

Checkout Building and customizing the menu bar with SwiftUI for guidance on native menu bars.

If you really don't want to have the built-in shortcut to open your app's settings in the Settings app, you can replace the children of the .preferences menu using UIMenuBuilder with your custom key command that brings up your app's settings.

Looks like this is something that works for now, unintended or not. Should that break in the future, I'll add my settings menu item alongside the system one. Thanks!

UIMainMenuSystem.shared.setBuildConfiguration(config) { builder in
            var items: [UIMenuElement] = []
            
            items.append(
                UIKeyCommand(
                    title: String(localized: "Settings..."),
                    image: UIImage(systemName: "gearshape"),
                    action: #selector(MainTabBarController.showSettings),
                    input: ",",
                    modifierFlags: [.command]
                )
            )
            
            items.append(
                UIKeyCommand(
                    title: String(localized: "Editor Settings..."),
                    image: UIImage(systemName: "textformat"),
                    action: #selector(MainTabBarController.showSettingsViewController),
                    input: ",",
                    modifierFlags: [.command, .alternate]
                )
            )
            
            items.append(
                UICommand(
                    title: String(localized: "System Settings..."),
                    image: UIImage(systemName: "gear"),
                    action: #selector(MainTabBarController.showSettingsViewController2)
                )
            )
            
            let menu = UIMenu(
                title: "Gamery",
                identifier: .application,
                options: .displayInline,
                children: items
            )
            
            builder.replace(menu: .application, with: menu)
        }
Replacing the Preferences item in a menu bar
 
 
Q