UIDeferredMenuElement on MacCatalyst: closure called only once on first menu display

Hi folks, I'm struggling with an issue on MacCatalyst. I'm using a dynamic menu that is supposed to show the current state of a setting (state = .on / .off). The UIDeferredMenuElement works great on iOS, the closure is called on each display of the (context) menu.

On MacCatalyst however - where I use the menu as a submenu in the main menu - the closure is called only once on first menu display. The system seems to show a cached menu item even though I'm using UIDeferredMenuElement.uncached.

Here's the relevant code:

func getMenuElement() {

let element = UIDeferredMenuElement.uncached { completion in

            let modeString = mode.myLocalizedDescription
            let trackingMode = <current setting>
            let mode = <menu item setting option>

            let state = trackingMode == mode ? .on : .off

            let action = UIAction(title: modeString,
                                  image: <image>,
                                  state: state) { _ in
                viewController.setUserTrackingMode(mode)
            }

            completion([action])
        }

        return element
}

Any ideas how to trick the system into generating the dynamic menu item on each menu display?

Confirm this for the main menu. uncached works only for context menus. Perhaps, the main menu (because of its persistence) needs to be rebuilt in order the closure ofUIDeferredMenuElement be called again.

Dynamic menu item for the main menu can be achieved through UIResponder.validate(_:). Also, you can call UIMenuSystem.main.setNeedsRebuild() to update all menu items.

UIDeferredMenuElement on MacCatalyst: closure called only once on first menu display
 
 
Q