NSServiceCache caches old data when writing a service in a Cocoa app

Hi!


I have created a service on a cocoa application, though this is my first cocoa app, I do have experience with iOS.

After testing it I was let known that this application does not work when selecting text from Apple Mail.


It will give an error: Report bug to Mantis (nl.uncinc.Mantis-bugreporter) is disqualified because its send and/or return types cannot be handled by the requestor (null).


Output of /System/Library/CoreServices/pbs -dump_pboard is the following:

{
        NSBundleIdentifier = "nl.uncinc.Mantis-bugreporter";
        NSBundlePath = "/Users/techwolf12/Library/Developer/Xcode/DerivedData/Mantis_bugreporter-csymyhiyhrzpkoaahasfxwenzzoa/Build/Products/Debug/Mantis bugreporter.app";
        NSKeyEquivalent =         {
            default = B;
        };
        NSMenuItem =         {
            default = "Report bug to Mantis";
        };
        NSMessage = menuReportBug;
        NSPortName = "Mantis bugreporter";
        NSRequiredContext =         {
        };
        NSRestricted = 0;
        NSReturnTypes =         (
              NSStringPboardType
        );
        NSSendTypes =         (
            NSStringPboardType,
            NSRTFPboardType,
            "public.plain-text"
        );


I think the issue is with the fact I had a return type in the past. However, /System/Library/CoreServices/pbs -flush, clean builds etc. do not work.

I also tried rm -rf /Users/techwolf12/Library/Developer/Xcode/DerivedData/* and a reboot of my machine already.


The part of my Info.plist is like this:

<key>NSServices</key>
    <array>
        <dict>
            <key>NSMessage</key>
            <string>menuReportBug</string>
            <key>NSKeyEquivalent</key>
            <dict>
                <key>default</key>
                <string>B</string>
            </dict>
            <key>NSMenuItem</key>
            <dict>
                <key>default</key>
                <string>Report bug to Mantis</string>
            </dict>
            <key>NSPortName</key>
            <string>Mantis bugreporter</string>
            <key>NSRequiredContext</key>
            <dict/>
            <key>NSRestricted</key>
            <false/>
            <key>NSSendTypes</key>
            <array>
                <string>NSURLPboardType</string>
                <string>NSFilenamesPboardType</string>
                <string>NSStringPboardType</string>
                <string>NSRTFPboardType</string>
                <string>NSRTFDPboardType</string>
            </array>
            <key>NSReturnTypes</key>
            <array/>
            <key>NSTimeout</key>
            <string>600000</string>
        </dict>
    </array>


And in my AppDelegate.m

- (void)applicationDidFinishLaunching:(NSNotification*)aNotification {
  ServiceHandler* handler;
  handler = [[ServiceHandler alloc] init];
  [NSApp setServicesProvider:handler];
  NSUpdateDynamicServices();
}


If someone would be able to help me, it will be very much appreciated!


Thanks!

After testing some more we came to the conclusion that apperantly pbs -flush & pbs -update do not work properly.

When manually checking the info.plist it shows the new values, when checking pbs -dump_pboard, it shows the old. Also after flushing/updating.


Suprisingly, if I remove the .app from Xcode/DerivedData it will not display anymore.

I also deleted the file located at /Users/techwolf12/Library/Caches/com.apple.nsservicescache.plist without success.

Accepted Answer

After trying a lot of different things, this has helped:


First, shutdown all your applications except a terminal.

In your terminal, execute the following:

rm -rf ~/Library/Developer/Xcode/DerivedData/*
/System/Library/CoreServices/pbs -flush


Also make sure you have no other versions of your .app on your disk.

Now, shut down your Mac (Don't just restart) and power it on again.

Run the following command:

/System/Library/CoreServices/pbs -flush


Now open Xcode and launch your app again.


This should work

NSServiceCache caches old data when writing a service in a Cocoa app
 
 
Q