cocoa

How to detect remote audio buttons on macOS?

孤街醉人 提交于 2021-01-27 16:05:03
问题 In the article Handling External Player Events Notifications Apple says that you need to do this: • Use the shared MPRemoteCommandCenter object to register handlers for the events you wish to handle and to disable the events you are not interested in receiving. • Begin playing audio. Your app must be the Now Playing app. An app does not receive remote control events until it begins playing audio. Test that your app is properly receiving and handling remote control events with Control Center,

NSSplitViewController/NSSplitViewItem support in XIBs

痞子三分冷 提交于 2021-01-27 14:24:19
问题 Is there support for NSSplitViewController/NSSplitViewItem for XIBs? I see only NSSplitView Can I just drag&drop NSViewController and subclass it as NSSplitViewController? How do I add NSSplitViewItem that it mostly works out of the box? I can easily see support for them in storyboards. 回答1: The split view controller is not part of the object library for xib files. The easiest way to use split view controllers is to use storyboards. If you are unwilling to use storyboards, your best option is

Getting exit status after launching app with NSWorkspace launchApplicationAtURL

假装没事ソ 提交于 2021-01-27 13:26:49
问题 I'm kind of new at Mac programming. I am porting a plugin to OSX. I need my application to launch a second app (which I do not control the source for) and then get its exit code. NSWorkspace launchApplicationAtURL works great to launch it with the needed arguments but I can't see how to get the exit code. Is there a way to get it after setting up notification for termination of the second app? I see tools for getting an exit code using NSTask instead. Should I be using that? 回答1: The

How to judge NSEvent from trackpad click, not tap to click

前提是你 提交于 2021-01-27 13:00:42
问题 When "tap to click" checked, how judge NSEvent is from trackpad click(pressed down) or tap to click. - (void)mouseEvent:(NSEvent*)theEvent { if ((type == NSLeftMouseUp || type == NSLeftMouseDown) && [theEvent subtype] == NSEventSubtypeTouch) { // How to detect touchpad is real pressed?? Not tap to cllick } } 回答1: To find out if someone only "tap to click" you could use func pressureChange(with event: NSEvent) in your NSViewController on NSView. If someone only "tap" the function will not be

Best practices for Xamarin.Mac MVVM pattern

六月ゝ 毕业季﹏ 提交于 2021-01-27 12:52:11
问题 I'm developing a WPF desktop application that I'd also like to run on Mac via Xamarin.Mac. I've taken great care to separate as much core code as possible into a PCL, and keep the WPF-specific code as thin as possible. The UI architecture is MVVM. All of my viewmodels, implementing INotifyPropertyChanged , in are in my core PCL. The WPF UI components can then directly bind to those viewmodel properties. My question is: how can I use my "portable" PCL viewmodels from the Xamarin.Mac side so

Custom-drawn tokens in NSTokenField

不打扰是莪最后的温柔 提交于 2021-01-27 12:29:31
问题 Is there a way to have custom tokens inside an NSTokenField ? By "custom" I mean I would like to draw them in a custom way -- custom hover, background image, etc. 回答1: Yes, this is possible, but you'll have to resort to using private APIs, which you don't want if you intend on publishing your app to the Mac App Store. I have contacted Apple about this, and they have confirmed that there is no way of doing this without private APIs - if one needs difference appearance using only public APIs,

how to toggle rich text formatting in NSTextView programmatically in cocoa

╄→尐↘猪︶ㄣ 提交于 2021-01-27 11:12:43
问题 I want to toggle rich text formatting in NSTextView. I have tried following: [contentView setRichText:NO]; [contentView setImportsGraphics:NO]; but, that didn't changed the NSTextView content and still allowing to do the text formatting. Please let me know the simple way to toggle/switch rich text formatting in NSTextView just like TextEdit. I already check the "TextEdit" sample project, but it seems to be very hard to find the usable code from it. Thanks 回答1: Found some help from following

how to toggle rich text formatting in NSTextView programmatically in cocoa

梦想的初衷 提交于 2021-01-27 11:11:58
问题 I want to toggle rich text formatting in NSTextView. I have tried following: [contentView setRichText:NO]; [contentView setImportsGraphics:NO]; but, that didn't changed the NSTextView content and still allowing to do the text formatting. Please let me know the simple way to toggle/switch rich text formatting in NSTextView just like TextEdit. I already check the "TextEdit" sample project, but it seems to be very hard to find the usable code from it. Thanks 回答1: Found some help from following

Highlighting NSStatusItem with attributed string

纵饮孤独 提交于 2021-01-27 04:14:31
问题 I have a NSStatusItem, and I use an attributed string for it, setting is as such: [statusItem setAttributedTitle:as]; where as is my attributed string. I use it to highlight certain parts of the item when certain conditions are met by coloring them differently. So my status item can have some red text and some black text, for example. Now the problem is, when I use setAttributedTitle and then click on the status item, the colors don't get inverted as I want them to. For instance, when I used

Getting current working directory from a Sandboxed command-line app

佐手、 提交于 2021-01-27 04:13:13
问题 I'm now trying to sandbox my command-line app which is written in Objective-C. Issue When the app was not sandboxed, I could get the directory where the user invoked the app using [[NSFileManager defaultManager] currentDirectoryPath] . However, after sandboxing, the app always returns for current directory /Users/{MY_ACCOUNT}/Library/Containers/{BUNDLE_IDENTIFIER}/Data no matter from where the command-line app was invoked. Example Code Actually, I wanna know the absolute path to the files