I am registering a contextual service in OS X via Xamarin.Mac. So far I have registered the service, written it, exported its signature and got the item showing up in Finder. However, whenever I invoke the context item, nothing happens. So far I have the following;
In ApplicationDelegate:
NSApplication.SharedApplication.ServicesProvider = _servicesProvider;
NSUpdateDynamicServices (); //using DllImport(Constants.AppKitLibrary) on an extern method
Then I have the following method signature on the NSObject
registered to my service, of which should be called:
[Export("testService:userData:error:")]
public void TestService(NSPasteboard pboard, NSString userData, NSString error)
{
TestAction ();
}
The Apple Documentation states that the signature should be of the form messageName:userData:error:
which I believe I have, however, it also references a double NSString
pointer in the required signature, ie:
- (void)simpleEncrypt:(NSPasteboard *)pboard userData:(NSString *)userData error:(NSString **)error
which has me thinking that the method isn't matching up properly.
Any suggestions out there?
Update
I poked my head into the system log and found this;
Cannot find service provider for selector testService:userData:error: or testService:: for service testService
which says to me the method is not being exported out correctly. It seems as if another user here had a similar quandary.
Update 2
Just to make sure my selector was working properly, I added a direct message invocation;
Messaging.void_objc_msgSend_IntPtr_IntPtr_IntPtr (_serviceProvider.Handle, _selector.Handle, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero);
Which performed the action perfectly fine (I used IntPtr.Zero
because the variables are required in the signature, but not used in my test case) which combined with the selector message in my initial question suggests that something isn't working right in the ServicesProvider
assignment.
I've been wrestling with this for a while. The method signature is the issue. The error argument is a double pointer. The correct method in c# is:
[Export("testService:userData:error:")]
public void TestService(NSPasteboard pboard, NSString userData, ref IntPtr error)
It now works without issues in my project.
Found the solution for double pointer at: https://forums.xamarin.com/discussion/56064/binding-project-nsmutablearray-pointer
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.