Man Liu
Man Liu

Reputation: 21

Mac services not working

I am currently writing an app to use system services to import an image.

I have followed all the steps from the Apple document about using services,

http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/SysServices/Articles/using.html#//apple_ref/doc/uid/20000854-CEGDDHJJ

but it didn't work.

I have a NSViewController and put

"[NSApp registerServicesMenuSendTypes:returnTypes:...]"

in the "initialize" function, and overwrite these functions: 'validRequestorForSendType', 'readSelectionFromPasteboard', 'writeSelectionToPasteboard'.

The "registerServicesMenuSendTypes:returnTypes" was called after I start the app, but none of the others are invoked, nor the service menu changes.

Can anyone help me with this or give me a good example to look at?

Thanks a lot.

Upvotes: 1

Views: 446

Answers (1)

Man Liu
Man Liu

Reputation: 21

Got the answer from apple: ( basicaly it would be more complicated to do this in the NSViewController, so I just implement it in a NSWindowController )

=============================================================================

Did your custom classes call -[NSApplication registerServicesMenuSendTypes:returnTypes:] early on in the application's lifetime, like in their +initialize method?

You say you're expecting -validRequestorForSendType:returnType: to be called on your window and view controllers (rather than the windows or views, themselves). However, that's not necessarily done. According to the documentation, that message is sent to the objects in the responder chain, plus NSApplication is documented as sending it to its delegate and NSWindow sends it to its delegate. It is important to note that a window controller is not necessarily the delegate of the window it controls. It can be. It may be common to set it up that way. But it is not automatically done by the framework. So, if you want the window controller to receive -validRequestorForSendType:returnType:, you need to make sure it's is the window's delegate.

I see nothing that suggests NSView will forward that message to its controller. Certainly, a generic view doesn't have a delegate. Even for those specific types of views that do have delegates (e.g. NSTabView), there's no documentation that views send -validRequestorForSendType:returnType: to their delegates. So, if you want a view controller to receive -validRequestorForSendType:returnType:, you'll have to ensure that it's in the responder chain (or write a custom view subclass that specifically forwards that message to its controller).

Upvotes: 1

Related Questions