如何使Finder的'开放'工作为我的应用程序(XCode,OS X)? [英] How to make Finder 'Open With' work for my application (XCode, OS X)?

查看:157
本文介绍了如何使Finder的'开放'工作为我的应用程序(XCode,OS X)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个能够播放音频文件的应用程序。这本身工作正常,从finder到我的应用程序拖放。

I have created an application that is capable of playing audio files. This in itself works fine, and so does drag&drop from finder to my application.

我想要的是,人们可以使用我的应用程序从Finder使用打开方式菜单(甚至允许他们将我的应用程序设置为某个文件类型的默认值)

What I would like as well, is that people can use my application from Finder using the Open With menu (or even allow them to set my application as default for a certain file type)

经过大量搜索,我发现我应该配置一个文档键入XCode(编辑信息属性列表
我成功添加了一个名为'Music File'的类型,其中包含UTI'public.mp3'
当我现在右键单击一个MP3文件时,我的应用程序列在打开方式菜单中。
尝试使用它,我的应用程序打开,但我收到一条警告消息无法打开文档。应用程序无法打开'音乐文件'格式的文件

After a lot of searching, I found that I should configure a document type in XCode (Editing information property lists) I successfully added such a type named 'Music File', with UTI 'public.mp3' When I now right-click an MP3 file, my application is listed in the 'Open With' menu. Trying to use it, my app opens, but I get a warning message saying "The document could not be opened. App cannot open files in the 'Music File' format"

它似乎不是通过命令行传递,就像在Windows中的情况。
我的应用程序支持从Finder拖放,这也很好。

It doesn't appear to be passed through the command line as is the case in Windows. My application does support drag&drop from Finder, and this is working fine too.

我真的不知道下一步看哪里,所以它会是伟大的,如果任何人可以指出我的方向正确。
我的应用程序没有使用NSDocument,所以'类'字段不适用于我我认为(根据文档这个字段不是必需的,但它不说如何处理它没有a class)

I don't really know where to look next, so it would be great if anyone could point me in the right direction. My application isn't using NSDocument, so the 'Class' field doesn't apply for me I think (and according to the docs this field isn't required, but it doesn't say how to handle it without a Class)

推荐答案

您实施 application:openFile: 在您的应用程式委托?这是当您的应用程序被要求从Finder打开文件时将被调用的方法。如果没有实现或者没有返回 YES ,那么框架将假设文件未成功打开,并将该事实报告给用户。

Do you implement application:openFile: in your app delegate? This is the method that will be called when your application is asked to open a file from the Finder. If it's not implemented or doesn't return YES, then the framework will assume that the file wasn't opened successfully and report that fact to the user.

这篇关于如何使Finder的'开放'工作为我的应用程序(XCode,OS X)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆