NSMetadataQuery忽略自定义文件包类型 [英] NSMetadataQuery ignoring custom file package type

查看:119
本文介绍了NSMetadataQuery忽略自定义文件包类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 UIManagedDocument 来管理我在iCloud中的文件。设置 NSMetadataQuery 之后如下:

I'm using UIManagedDocuments to manage my files in iCloud. After setting up the NSMetadataQuery like so:

iCloudQuery = [[NSMetadataQuery alloc] init];
[iCloudQuery setSearchScopes:
    [NSArray arrayWithObject:NSMetadataQueryUbiquitousDocumentsScope]];
[iCloudQuery setPredicate:
    [NSPredicate predicateWithFormat:@"%K like %@", NSMetadataItemFSNameKey, @"DocumentMetadata.plist"]];

我遇到了一个奇怪的问题 - 当我的文件被命名没有文件扩展名时(例如 @NewDocument2)或公共扩展名如 .txt ,元数据查询正确找到 DocumentMetadata.plist 文件。但是,当使用我的自定义文件扩展名时,查询永远不会找到任何内容......不是在查询开始时,也不是在我添加新文档时。

I'm encountering a curious problem - when my documents are named without a file extension (for example @"NewDocument2") or a public extension like .txt, the metadata query correctly finds the DocumentMetadata.plist file. However, when using my custom file extension, the query never finds anything... not when the query starts, nor when I add a new document.

在我看来该查询可能正在查看我的文档及其自定义文件扩展名,并未意识到它实际上是目录(无论如何都是文件包),所以不会在里面查找 DocumentMetadata.plist 文件。但是,我已经在应用程序的 info.plist 中声明了我的自定义UTI。

It seems to me that the query is probably seeing my document with its custom file extension, is not realising that it is, in fact, a directory (a file package at any rate), and so does not look inside to find the DocumentMetadata.plist file. However, I have declared my custom UTI in the app's info.plist.

也许我已经错误地声明了我的UTI ?我遵循了Apple的指导原则(在基于文档的iOS应用程序编程指南统一类型标识符概述)创建它,但似乎出了问题。

Perhaps I have declared my UTI wrongly? I followed Apple's guidelines (in the Document-Based App Programming Guide for iOS and Uniform Type Identifiers Overview) in creating it, but it seems like something is wrong.

编辑: info.plist 中的'导出的UTI'下,我的类型已设置符合'com.apple.package'。

Under 'Exported UTIs' in the info.plist, my type is set to conform to 'com.apple.package'.

编辑:
我还在努力解决这个问题。我现在正在解决它没有使用文件扩展名。

I'm still struggling with this issue. I'm working around it for now by not using a file extension.

使用自定义文件扩展名时,我正在处理iCloud元数据查询结果和 DocumentMetadata.plist 文件肯定在文件包中,但元数据查询无法看到它。枚举查询结果时,会在日志中打印以下内容:

When using the custom file extension, I'm processing the iCloud metadata query results and the DocumentMetadata.plist file is definitely inside the file package, but the metadata query can't see it. When enumerating the query results, the following is printed to the log:

<iCloud Container URL>/Documents/
<iCloud Container URL>/Documents/New%20Document.spdoc/
<iCloud Container URL>/Documents/New%20Document.spdoc/DocumentMetadata.plist
<iCloud Container URL>/Documents/New%20Document.spdoc/StoreContent.nosync/
<iCloud Container URL>/Documents/New%20Document.spdoc/StoreContent.nosync/(A%20Document%20Being%20Saved%20By%20<AppName>%202)/
<iCloud Container URL>/Documents/New%20Document.spdoc/StoreContent.nosync/(A%20Document%20Being%20Saved%20By%20<AppName>)/
<iCloud Container URL>/Documents/New%20Document.spdoc/StoreContent.nosync/.persistentStore_SUPPORT/
<iCloud Container URL>/Documents/New%20Document.spdoc/StoreContent.nosync/.persistentStore_SUPPORT/_EXTERNAL_DATA/
<iCloud Container URL>/Documents/New%20Document.spdoc/StoreContent.nosync/persistentStore

(CoreDataLogs目录中还有一堆文件,但是我为简洁而没有在这里显示它们。

我只能认为这个问题与错误地创建我的文件包UTI有关。有没有其他人成功使用iCloud的自定义文件包?这是一个错误吗?

I can only think that this problem is something to do with incorrectly creating my file package UTI. Has anybody else successfully used custom file packages with iCloud? Is this a bug?

推荐答案

这是设计的。

API也适用于Spotlight。它不应该下载到包文档中,因为这些文档的内容基本上是私有的。对于iCloud,这并没有太多意义,但我怀疑它们不会改变它。根据API的使用位置,API以两种不同的方式工作是没有意义的。

The API works this way for Spotlight as well. It shouldn't descend into package documents because the contents of those documents are basically private. With iCloud, this doesn't make all that much sense, but I suspect that they won't be changing it. It wouldn't make sense for the API to work in two different ways depending on where it's being used.

我想这是历史性的事情 - 在Mac上你可以实现Spotlight导入程序,用于处理自定义文档类型。在iOS上,我认为这还不可能(如果我错了,请纠正我)。所以现在,您只需要解决API的这个功能。

I guess this is a historic thing — on Mac you can implement a Spotlight importer to handle your custom document type. On iOS, I don't think this is possible yet (correct me if I'm wrong). So for now, you just have to work around this 'feature' of the API.

您可以搜索文档,然后从那里获取元数据。否则,按照您的方式链接扩展名应该可以正常工作。

You can search for the document instead and then just get the metadata from there. Otherwise, chaining the extension as you have done should work.

这篇关于NSMetadataQuery忽略自定义文件包类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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