0

I'm trying to build an application that easily converts from one file format to another. The idea is you drag the source file onto the dock tile and the output file is created alongside the source file (in the same directory.)

After reading the documentation, I have everything setup correctly -- I think... but it doesn't work.

My Info.plist contains the following:

<key>CFBundleDocumentTypes</key>
<array>
    <dict>
        <key>CFBundleTypeExtensions</key>
        <array>
            my_src_type
        </array>
        <key>CFBundleTypeRole</key>
        <string>Viewer</string>
        [...]
    </dict>
    <dict>
        <key>CFBundleTypeExtensions</key>
        <array>
            my_dest_type
        </array>
        <key>CFBundleTypeRole</key>
        <string>Editor</string>
        <key>NSIsRelatedItemType</key>
        <true/>
        [...]
    </dict>
</array>

If I'm reading the documentation correctly, this should allow my app to accept files of my_src_type via drag and drop and output files of my_dest_type in the same directory as the input file, provided of course that I let the sandbox know about it.

To that end, I have a SimpleFilePresenter that looks like this:

 @interface SimpleFilePresenter : NSObject<NSFilePresenter>
 @property (atomic, strong) NSURL *presentedItemURL;
 @property (atomic, strong) NSURL *primaryPresentedItemURL;
 @end

 @implementation SimpleFilePresenter
 - (NSOperationQueue *)presentedItemOperationQueue {
         return [NSOperationQueue mainQueue];
 }
 @end

As soon as I use addFilePresenter: to request permission to create my output file, I get the following error in the Console.

2013-04-26 6:33:52.741 PM my_app[27639]: NSFileSandboxingRequestRelatedItemExtension: an error was received from pboxd instead of a token. Domain: NSPOSIXErrorDomain, code: 1
2013-04-26 6:33:52.741 PM my_app[27639]: +[NSFileCoordinator addFilePresenter:] could not get a sandbox extension. primaryPresentedItemURL: file://[...]/file.my_src_type, presentedItemURL: file://[...]/file.my_dest_type
4

2 回答 2

1

结果addFilePresenter:不是同步的或瞬时的我所要做的就是调用[NSFileCoordinator filePresenters]addFilePresenter:似乎具有阻塞的效果,直到所有文件演示者都准备好去。

另外,我正在使用 Qt,所以我很惊喜地发现这一切都可以正常工作,而无需NSURL从看起来更可怕的NSFileCoordinator方法中获取特别创建的对象。

于 2013-04-27T03:43:29.940 回答
0

此错误的另一个原因可能是项目信息文件中的 UTI 定义不正确或缺失。

必须为文档类型定义 UTI,并且它应该与 UTI 定义的导入/导出 UTI 部分相同(如果它不是内置 UTI)。

于 2013-07-03T17:09:27.050 回答