Fixing a CommandMenu causing UIMenuController - unrecognized selector

I have a SwiftUI app I have enabled to run on M1 Macs (Designed for iPad). It uses the new SwiftUI lifecycle.

I've just added a CommandMenu to the main WindowGroup.

On the iPad these commands, whether clicked in the menu or initiated by a keyboard shortcut work as expected on the iPad.

However, my iMac, the app crashes. The error says

Application Specific Information:
Crashing on exception: -[UIMenuController propertyList]: unrecognized selector sent to instance 0x12250b1e0

This is what the CommandMenu looks like

WindowGroup {
...
}.commands {

        CommandMenu(LocalizedStringKey("Categories")) {

            Button(action:{

                appConfiguration.currentPage = Page.books

            }) {

                Label(LocalizedStringKey(BookListing.title), systemImage: BookListing.icon)

            }

            .keyboardShortcut("b", modifiers: [.control])



            Button(action:{

                appConfiguration.currentPage = Page.tags

            }) {

                Label(LocalizedStringKey(Tags.title), systemImage: Tags.icon)

            }

            .keyboardShortcut("t", modifiers: [.control])



            Button(action:{

                appConfiguration.currentPage = Page.settings

            }) {

                Label(LocalizedStringKey(Settings.title), systemImage: Settings.icon)

            }

            .keyboardShortcut("s", modifiers: [.control])

        }

    }

AppConfiguration is an ObservableObject and setting currentPage is how to programmatically navigate the TavView.

Is there anything I am doing wrong?

Is there a bug someone knows about that I could be hitting?

Here's the relevant part of the stack if that can help shed some light on what's gone wrong.

Thread 0 Crashed::  Dispatch queue: com.apple.main-thread
0   AppKit                        	       0x191895514 -[NSApplication _crashOnException:] + 324
1   AppKit                        	       0x19189550c -[NSApplication _crashOnException:] + 316
2   AppKit                        	       0x19189522c -[NSApplication reportException:] + 580
3   AppKit                        	       0x19193f708 uncaughtErrorProc + 156
4   HIToolbox                     	       0x1975b10bc DispatchEventToHandlers(EventTargetRec*, OpaqueEventRef*, HandlerCallRec*) + 1696
5   HIToolbox                     	       0x1975b02dc SendEventToEventTargetInternal(OpaqueEventRef*, OpaqueEventTargetRef*, HandlerCallRec*) + 356
6   HIToolbox                     	       0x1975c6750 SendEventToEventTarget + 40
7   HIToolbox                     	       0x197627310 SendHICommandEvent(unsigned int, HICommand const*, unsigned int, unsigned int, unsigned char, void const*, OpaqueEventTargetRef*, OpaqueEventTargetRef*, OpaqueEventRef**) + 416
8   HIToolbox                     	       0x19764c44c SendMenuCommandWithContextAndModifiers + 56
9   HIToolbox                     	       0x19764c3dc SendMenuItemSelectedEvent + 352
10  HIToolbox                     	       0x19764c208 FinishMenuSelection(SelectionData*, MenuResult*, MenuResult*) + 100
11  HIToolbox                     	       0x19764cbc8 MenuSelectCore(MenuData*, Point, double, unsigned int, OpaqueMenuRef**, unsigned short*) + 560
12  HIToolbox                     	       0x19764c8e8 _HandleMenuSelection2 + 416
13  AppKit                        	       0x1916b4ce4 _NSHandleCarbonMenuEvent + 300
14  AppKit                        	       0x1916b4ac4 _DPSEventHandledByCarbon + 68
15  AppKit                        	       0x191516bc4 -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 3280
16  AppKit                        	       0x1915085f0 -[NSApplication run] + 596
17  AppKit                        	       0x1914d9d08 NSApplicationMain + 1132
18  AppKit                        	       0x1917afdd0 _NSApplicationMainWithInfoDictionary + 24
19  UIKitMacHelper                	       0x1a423aa7c UINSApplicationMain + 1276
20  UIKitCore                     	       0x1b68d59f8 UIApplicationMain + 164
21  SwiftUI                       	       0x1cc162374 closure #1 in KitRendererCommon(_:) + 164
22  SwiftUI                       	       0x1cc1622cc runApp<A>(_:) + 252
23  SwiftUI                       	       0x1cba55560 static App.main() + 128

I've noticed if I create a CommandMenu without a keyboardShortcut of any kind then it does not crash. So, I suspect the issue is around there.

Considering the type of error being related to selectors, I've tried changing my event modifiers to be the full definition (example EventModifiers.control rather than .control) and that does not seem to help either.

I should have noted, this is on Montery 12.3.1 and the iPad app targets iOS 15.0

Same problem

Same here using Xcode 15.1 beta.

I filed a report in Feedback Assistant as well: FB13258087

Fixing a CommandMenu causing UIMenuController - unrecognized selector
 
 
Q