I am using the SwiftUI App to build a multi-platform app. However, on macOS, the "Emoji & Symbols" command that normally appears in the "Edit" menu does not show up. Additionally, the typical keyboard shortcut will not open that Emoji picker in my app. Is there a way to enable that command?
macOS Emoji picker does not work in SwiftUI App
I'm also seeing this in a SwiftUI multiplatform app which I created with the first beta of Xcode 12.
Projects created with the latest version of Xcode (12.4 as I write this) add this menu item just fine, but I'm not sure how to get it to show up in the old project.
Projects created with the latest version of Xcode (12.4 as I write this) add this menu item just fine, but I'm not sure how to get it to show up in the old project.
I was seeing this when running my app on macOS 11; so for older versions, I added the menu option manually to get the keyboard shortcut working as expected.
On your WindowGroup
in your App
file:
.commands {
CommandGroup(after: CommandGroupPlacement.textEditing) { // place the new command after existing text editing commands
if ProcessInfo().operatingSystemVersion.majorVersion < 12 { // only add for specific versions
Button {
NSApplication.shared.orderFrontCharacterPalette(nil) // to open the emoji popover
} label: {
Text("Emoji & Symbols") // match what is added automatically on newer versions
}
.keyboardShortcut(.space, modifiers: [.control, .command]) // match what is added automatically on newer versions
}
}
}