简体   繁体   English

Finder NSService上下文菜单错误与:找不到选择器的服务提供者

[英]Finder NSService Context Menu errors with: Cannot find service provider for selector

UPDATE 1: Getting closer 更新1:越来越近

Someone on IRC mentioned that my NSPortName should be my application, not Finder. IRC上有人提到我的NSPortName应该是我的应用程序,而不是Finder。 I changed this and now I'm seeing a log message in my app when the context menu is selected: 我更改了此设置,现在在选择上下文菜单时在我的应用程序中看到一条日志消息:

Cannot find service provider for selector shareFile:userData:error: or shareFile:: for service shareFile

This seems odd considering I do have such an object registered. 这似乎很奇怪考虑到我有这样一个对象注册。


I am trying to setup an NSService contextual menu for Finder to trigger my app on certain files. 我正在尝试为Finder设置NSService上下文菜单,以在某些文件上触发我的应用程序。

The files have extension *.acxx and the action is simply to share. 这些文件的扩展名为* .acxx,操作仅是共享。 Note: I've changed all references of the bundle to be generic for this posting: com.mycompany.myproject. 注意:对于此发布,我已将捆绑软件的所有引用更改为通用:com.mycompany.myproject。

My NSServices section of my infoPlist looks like this: (Note i have Document TYpes/UTIs setup for *.acxx as well) 我的infoPlist的NSServices部分如下所示:(请注意,我也为* .acxx设置了文档类型/ UTI)

<key>NSServices</key>
    <array>
        <dict>
            <key>NSRequiredContext</key>
            <dict>
                <key>NSTextContent</key>
                <array>
                    <string>URL</string>
                    <string>FilePath</string>
                </array>
            </dict>
            <key>NSSendFileTypes</key>
            <array>
                <string>com.mycompany.myproject.acxx</string>
            </array>
            <key>NSPortName</key>
            <string>Finder</string>
            <key>NSMessage</key>
            <string>shareFile</string>
            <key>NSMenuItem</key>
            <dict>
                <key>default</key>
                <string>Share with myproject</string>
            </dict>
        </dict>
    </array>

I have an object setup in my code that has the following method defined: 我的代码中有一个对象设置,其中定义了以下方法:

- (void)shareFile:(NSPasteboard*)pboard userData:(NSString*) error:(NSString**)err

And I register this elsewhere in my code: 我在我的代码中的其他地方注册:

// Register services
if (self.shareSvcMgr == nil)
{
    self.shareSvcMgr = [[ACAShareServiceManager alloc] init];
}
[NSApp setServicesProvider:self.shareSvcMgr];
NSUpdateDynamicServices();

Now, when I run the app and then make sure it's registered with pbs, it looks fine: 现在,当我运行该应用程序并确保它已在pbs中注册时,它看起来不错:

/System/Library/CoreServices/pbs -debug en|grep -i myproj
        NSBundleIdentifier = "com.mycompany.myproject";
        NSBundlePath = "/Users/me/Library/Developer/Xcode/DerivedData/myproject-gihhiqhnzhwqbchflymzyafwxvws/Build/Products/Debug/myproject.app";
            default = "Share with myproject";
            "com.mycompany.myproject.acxx"

So when I go to the Finder and click on a *.acxx file, sure enough in Finder -> Services, my menu item Share with myproject shows up. 因此,当我转到Finder并单击* .acxx文件时,在Finder-> Services中确保足够,我的菜单项“与myproject共享”就会显示出来。

PROBLEM: 问题:

All is fine and dandy right? 一切都很好,对吗? Well no. 好吧 When I click 'share with myproject', nothing happens. 当我单击“与我的项目共享”时,什么也没有发生。 I have a breakpoint setup in the shareFile method and the program is running and yet nothing happens, it never gets hit, etc. 我在shareFile方法中有一个断点设置,程序正在运行,但是什么也没发生,它从未被击中,等等。

I had read that I could debug the Finder using -NSDebugServices but I can't seem to get that to work right. 我读过我可以使用-NSDebugServices调试Finder,但似乎无法正常工作。 I've executed: 我已经执行了:

/System/Library/CoreServices/Finder.app/Contents/MacOS/Finder -NSDebugServices com.mycompany.myproject

This seems to start up a process but I get no Finder window to try to interact with. 这似乎启动了一个过程,但是我没有找到与之交互的Finder窗口。

I'm not sure where to go next. 我不确定下一步要去哪里。 The idea of course is to pass the filename or file contents to my application when Share is sent and then I can do what is needed with it from there. 当然,其想法是在发送共享时将文件名或文件内容传递给我的应用程序,然后我可以从那里执行所需的操作。

Are the SendFileTypes not setup right or something for this model? 是SendFileTypes设置不正确还是适用于该模型? Any help appreciated. 任何帮助表示赞赏。 Thanks 谢谢

Alright. 好的。 Someone on IRC pointed out that my method definition was missing something: IRC上的某人指出我的方法定义缺少一些内容:

- (void)shareFile:(NSPasteboard*)pboard userData:(NSString*) error:(NSString**)err

It was missing a variable definition (which can totally mess up the selector matching). 它缺少变量定义(这可能完全搞乱选择器匹配)。 So it should have been this: 因此应该是这样的:

- (void)shareFile:(NSPasteboard*)pboard userData:(NSString*)***udata*** error:(NSString**)err

Once I changed that, the selector finally started getting called =) 一旦我更改了它,选择器终于开始被调用=)

I ran into the same issue and was able to resolve this by deleting derived data. 我遇到了同样的问题,并且能够通过删除派生数据来解决此问题。

I think what happened was that I was trying to test something by creating a dummy app, and I used the same message name for the service. 我认为发生的事情是我试图通过创建虚拟应用程序来测试某些东西,并且为该服务使用了相同的消息名称。 By deleting the derived data from the dummy app, everything started to work. 通过删除虚拟应用程序中的派生数据,一切开始起作用。

You should be able to find the derived data in a directory somewhere in this path: 您应该能够在此路径下的某个目录中找到派生数据:

~/Library/Developer/Xcode/DerivedData/

Remove the old stuff, and it might resolve it for you. 删除旧的东西,它可能会为您解决。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM