Thank you for the help @robnotyou
I was unable to drag any segue onto my other vc's, but your answer prompted me to find a way.
In the storyboard I clicked on the "Application Help" and saw it had a sent action to the first responder.
Selecting the "Main Menu Scene" in the storyboard then viewing the first responder outlets, it said the button was connected to an action "showHelp", with a warning sign that the action is not defined. So I added this code to my appDelegate:
@IBAction func showHelp(_ sender: Any) {
let mess = NSLocalizedString("mac menu bar help instructions", comment: "")
let alert = UIAlertController(title: nil, message: mess, preferredStyle: UIAlertController.Style.alert)
alert.addAction(UIAlertAction(title: NSLocalizedString("okay", comment: ""), style: UIAlertAction.Style.default, handler: nil))
self.window?.rootViewController?.present(alert, animated: true, completion: nil)
}
By calling the method the default alert controller is no longer displayed, but the code I above recreates the default alert, but allows me to alter the contents.
This achieved what I was after, thanks again.
Post
Replies
Boosts
Views
Activity
I found the solution:
I found this page on adding hardware keyboard support to your app which had the answer: https://developer.apple.com/videos/play/wwdc2020/10109/
To achieve this you simply override the UIKeyCommand property in the view controller class you want the shortcut to be available in and set the properties accordingly, example below. You may also need to ensure your vc is the first responder.
override var keyCommands: [UIKeyCommand]? {
if #available(iOS 13.0, *) {
return [
UIKeyCommand(title: "test action", action: #selector(keyPressureTest), input: "m", modifierFlags: .command),
UIKeyCommand(title: "test action 2", action: #selector(keyPressureTest), input: "m")
]
} else {
// Fallback on earlier versions
return []
}
}
@objc func keyPressureTest() {
print("shortcut action completed")
}
I was running the extension scheme and still not seeing breakpoints or print statements. I got it to work by having the widget extension running, and then running the application scheme.
Make sure your image is a part of the assets for the right bundle if you have multiple targets.
I have the same issue and know a fix for this and possibly the reason.
The fix is to go into the system preferences -> Sound, then go to input and change the input source to something other than your headphones. (shortcut: option + any volume key)
I don't know how to fix this at an Xcode level, or if you only have one input device though.
Just for anyone who cares, the reason for the stuffy audio is that Xcode starts a phone call, and I suppose my headphones don't like to output clean sound with the mic taking inputs.
I know that Xcode is starting a call because my headphones have bluetooth multipoint, as well as giving me verbal feedback about whats going on with them.
When bluetooth multipoint is active my audio will switch cleanly between my iMac and Ipad pro, unless one of them is taking a phone call then the phone call will get priority.
When I get this muffled audio, my headphones won't switch to my Ipad to play audio, which suggests that a phone call is in progress.
What really says that a call is in progress, is that when I change the input source in system preferences away from my headphones, the audio clears up but my headphones also say "call ended".
All this means that Xcode must be starting a phone call for some reason, and my headphones don't like that.
Why my iMac speakers are happy to play music while "taking a phone call" but my headphones aren't may mean that it isn't a macOS issue but a limitation with the headphones, but this is just guess work.
attach this to your view. works in macos
.contextMenu {
Button("Remove") {
print("remove this view")
}
}
I had the same problem on my universal SwiftUI app. problem was one of the files I made (the one I defined my struct in), didn't have the macOS target selected.
@main
struct MyApp: App {
var body: some Scene {
WindowGroup {
ContentView()
}
#if canImport(AppKit)
.windowStyle(.hiddenTitleBar)
#endif
}
}