Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Showing an NSSharingServicePicker on MouseUp

Tags:

macos

cocoa

I'm adding sharing to my app (targeting Mavericks, 10.9), which I want to work like this:

  1. User clicks Share button
  2. Cursor changes to crosshair
  3. User drags selection of what he'd like to share
  4. NSSharingServicePicker displays, allowing the user to pick the service to share with

I'm accomplishing this using the -mouseDown:, -mouseDragged:, and -mouseUp: events. mouseDown begins the selection, mouseDragged provides feedback as to the area being selected, and then mouseUp completes the drag, showing the picker. Each time, though, I get this written to the console:

2014-06-25 00:13:45.111 App[31401:303] Warning: -[NSSharingServicePicker showRelativeToRect: ofView: preferredEdge:] should not be called on mouseUp
Please configure the sender with -[NSControl sendActionOn:NSLeftMouseDownMask];

I don't understand why that would be a problem, unless you were showing it from a button click on mouse up. Should I ignore the message? I've tried showing it using dispatch_async and dispatch_after to try and get it to run outside the event's invocation, but they didn't work. I suppose I could ignore it, but does that leave the door to deprecation open?

like image 830
Dov Avatar asked Jun 25 '14 13:06

Dov


1 Answers

I know this is a year late but,
I had the same problem. After some research, I cam back with this answer. Before I implemented this code, my button would spin for a while, and then return with the same error you had. When I click my share button now, it no longer lags, and does not return any error. Insert this into your app's awakeFromNib method:[yourShareButtonName sendActionOn:NSLeftMouseDownMask];. This is what your code should look like:

- (void)awakeFromNib {
    [yourShareButtonName sendActionOn:NSLeftMouseDownMask];
}

I hope this helps!

like image 180
SGP Avatar answered Oct 15 '22 13:10

SGP