NSMetadataQuery找不到NSFileWrapper文件夹包,只有文件(但他们在那里) [英] NSMetadataQuery does not find NSFileWrapper folder bundles, only files (but they're there)

查看:260
本文介绍了NSMetadataQuery找不到NSFileWrapper文件夹包,只有文件(但他们在那里)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个奇怪的问题,我似乎无法解决我自己。任何帮助或想法。



    b
  • NSMetadataQuery查找正常文件(如test.txt),但找不到文件包
    bundle(myWrapperDocument.pro)

  • 但是,NSFileManager会查找我的无处不在容器中的所有文件 -



    • 使用NSFileWrappers的基于UIDocument的应用程序

    • 共享Ubiquity容器(适用于iOS和桌面应用程序)

    • 在Mac OS上运行完美

    • 在我的iPad Mini和我的iPhone 4S和iPhone 3GS(运行iOS6和iOS5)上工作完美

    • 不适用于我的iPad1或我的大多数测试版设备(运行iOS5或6的iPad 1,2和3)



    到目前为止我做了什么:




    • 研究了WWDC12 UIDocument&

    • 测试了许多不同的谓词,检查了权利。和文档设置(所以系统知道它不是文件夹,而是文档包)

    • 清除和重置Ubiquity容器



    相关代码:



    授权应该正确;
    Info.plist文档设置(我认为文档类型已正确注册)

     < key> CFBundleDocumentTypes< / key> 
    < array>
    < dict>
    < key> CFBundleTypeExtensions< / key>
    < array>
    < string> pro< / string>
    < / array>
    < key> CFBundleTypeName< / key>
    < string> Prowriting Sketch< / string>
    < key> LSItemContentTypes< / key>
    < array>
    < string> de.ac.prowriting.sketch< / string>
    < / array>
    < key> LSTypeIsPackage< / key>
    < true />
    < / dict>

    ...

    < key> UTExportedTypeDeclarations< / key>
    < array>
    < dict>
    < key> CFBundleTypeExtensions< / key>
    < array>
    < string> pro< / string>
    < / array>
    < key> LSTypeIsPackage< / key>
    < true />
    < key> UTTypeConformsTo< / key>
    < array>
    < string> com.apple.package< / string>
    < / array>
    < key> UTTypeDescription< / key>
    < string> Prowriting Sketch< / string>
    < key> UTTypeIdentifier< / key>
    < string> de.ac.prowriting.sketch< / string>
    < / dict>

    无处不在的容器和iCloud文档url都很好,这是我如何设置查询: / p>

       - (void)startMetadataQuery {
    // ...
    [self.query setSearchScopes:@ [ NSMetadataQueryUbiquitousDocumentsScope]];

    //搜索所有.pro文档,也尝试其他谓词,见下面
    NSString * predicate = [NSString stringWithFormat:@%K like'*'];
    [self.query setPredicate:[NSPredicate predicateWithFormat:predicate,NSMetadataItemFSNameKey]];

    // register observer(...)
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didFinishMetadataQuery :) name:NSMetadataQueryDidFinishGatheringNotification object:nil];

    [self.query startQuery];
    }

    - (void)didFinishMetadataQuery:(NSNotification *)notification {
    [self.query disableUpdates];
    NSLog(@+++ found%i results:\\\
    %@,self.query.resultCount,self.query.results);
    NSLog(@+++ iCloud文件夹中的结果:%i,[self.fileManager contentOfDirectoryAtPath:self.iCloudDocumentsFolder.path error:nil] .count);
    }

    真的很奇怪的是,只有一个文件test.txt,但其他仍然未被检测。但是从日志中可以看到,容器有84个.pro文件(所有名为something.pro),但查询只查找一个test.txt。



    不幸的是,使用NSFileManager访问这些文件不是一个选项,因为我似乎没有权限读这些。

      2013-02- 18 +++ found 1 results:(< NSMetadataItem:0x3ac390> / private / var / mobile / Library / Mobile Documents / ABCD123456〜de〜ac〜prowriting / Documents / test.txt)
    2013-02 -18 +++ iCloud文件夹中的结果:84

    我认为这是谓词, p>

      @%K like'* .pro *'//不返回任何值
    @%% K like'* 。*'//只返回test.txt文件
    @%% K like'*'//只返回test.txt文件
    @%K LIKE *//返回只有test.txt文件
    @NSMetadataItemFSNameKey =='*'//只返回test.txt文件

    我真的不知道该怎么办。
    最奇怪的是,它可以在某些设备上工作,而不在其他设备上工作。



    我会非常感谢任何提示问题。非常感谢!

    解决方案

    奇怪的是,我不得不 删除

     < key> LSItemContentTypes< / key>的 LSItemContentTypes  
    < array>
    < string> de.ac.prowriting.sketch< / string>
    < / array>

    此设置是为什么我导出的自定义UTI文件包装器文件类型无法正确识别为文件,解释为文件夹。 NSMetadataQuery不查询文件夹,这就是为什么它没有找到我的任何文件。



    不幸的是我也有一个Mac应用程序,我的自定义文件类型在桌面上正确注册影响移动文档iCloud文件夹;所以这是为什么它工作在我的大多数设备,但没有我的测试者。


    I have a strange problem which I can't seem to solve on my own. Any help or thought is appreciated.

    The problem:

    • NSMetadataQuery finds normal files (like test.txt) but no filewrapper bundle (myWrapperDocument.pro)
    • However, NSFileManager finds all files in my ubiquity container - so the files are there, but NSMetadataQuery doesn't find them!

    The facts:

    • UIDocument based app using NSFileWrappers
    • Shared Ubiquity Container (for iOS and Desktop app)
    • Works perfect on Mac OS
    • Works perfect on my iPad Mini and my iPhone 4S and iPhone 3GS (running iOS6 and iOS5)
    • Doesn't work on my iPad1 nor on most of my beta tester's devices (iPads 1,2&3 running iOS5 or 6)

    What I did so far:

    • Studied WWDC12 UIDocument & iCloud example (CloudNotes.xcodeproj)
    • Studied hours in Apple's dev forum and here, unfortunately without any luck
    • Tested many different predicates, checked the entitlements and the document setup (so the system knows, that it's not a folder, but a document bundle)
    • Clearing and resetting the Ubiquity container

    The relevant code:

    Entitlements should be correct; Info.plist document setup ( I think the document type has been registered correctly )

    <key>CFBundleDocumentTypes</key>
        <array>
      <dict>
          <key>CFBundleTypeExtensions</key>
          <array>
            <string>pro</string>
          </array>
          <key>CFBundleTypeName</key>
          <string>Prowriting Sketch</string>
          <key>LSItemContentTypes</key>
          <array>
            <string>de.ac.prowriting.sketch</string>
          </array>
          <key>LSTypeIsPackage</key>
          <true/>
      </dict>
    
      …
    
      <key>UTExportedTypeDeclarations</key>
        <array>
        <dict>
          <key>CFBundleTypeExtensions</key>
          <array>
            <string>pro</string>
          </array>
          <key>LSTypeIsPackage</key>
          <true/>
          <key>UTTypeConformsTo</key>
          <array>
            <string>com.apple.package</string>
          </array>
          <key>UTTypeDescription</key>
          <string>Prowriting Sketch</string>
          <key>UTTypeIdentifier</key>
          <string>de.ac.prowriting.sketch</string>
        </dict>
    

    The ubiquity container and iCloud documents url are all fine, this is how I set up the query:

    - (void)startMetadataQuery {
      // ...
      [self.query setSearchScopes:@[NSMetadataQueryUbiquitousDocumentsScope]];
    
      // search for all .pro documents, also tried other predicates, see below
      NSString *predicate = [NSString stringWithFormat:@"%K like '*'"];
      [self.query setPredicate:[NSPredicate predicateWithFormat:predicate, NSMetadataItemFSNameKey]];
    
      // register observer (...)
      [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didFinishMetadataQuery:) name:NSMetadataQueryDidFinishGatheringNotification object:nil];
    
      [self.query startQuery];
    }
    
    - (void)didFinishMetadataQuery:(NSNotification*)notification {
        [self.query disableUpdates];
        NSLog(@"+++ found %i results: \n%@", self.query.resultCount, self.query.results);
        NSLog(@"+++ Results in iCloud folder: %i", [self.fileManager contentsOfDirectoryAtPath:self.iCloudDocumentsFolder.path error:nil].count);
    }
    

    The really strange thing is, that the query returns with just one file "test.txt", but the others remain undetected. But as you can see from the log, the container has 84 .pro files (all called "something.pro"), but the query only finds the one "test.txt".

    Unfortunately accessing these files with NSFileManager isn't an option, as I don't seem to have the rights to read those. I don't think my container's corrupt as this issue also happens on fresh installations of my beta tester's devices?

    2013-02-18 +++ found 1 results: ("<NSMetadataItem: 0x3ac390> /private/var/mobile/Library/Mobile Documents/ABCD123456~de~ac~prowriting/Documents/test.txt")
    2013-02-18 +++ Results in iCloud folder: 84
    

    I think it's the predicate, but:

    @"%K like '*.pro*'"                // returns nothing
    @"%%K like '*.*'"                  // returns only the test.txt file
    @"%%K like '*'"                    // returns only the test.txt file
    @"%K LIKE *"                       // returns only the test.txt file
    @"NSMetadataItemFSNameKey == '*'"  // returns only the test.txt file
    

    I really don't know what to do anymore. The most strange thing is, that it works on some devices while not working at all on other devices.

    I would be super thankful for any hint on this issue. Thanks a lot!

    解决方案

    strangely enough, I had to remove the LSItemContentTypes setting from the info.plist file:

    <key>LSItemContentTypes</key>
      <array>
        <string>de.ac.prowriting.sketch</string>
      </array>
    

    this setting was the reason, why my exported custom UTI filewrapper filetype was not recognized properly as file, but interpreted as folder. NSMetadataQuery does not query folders, that's why it didn't find any of my files.

    Unfortunately I also have a Mac app and my custom filetype was registered correctly on the desktop affecting the Mobile Documents iCloud folder; so that was the reason why it worked on most of my devices, but on none of my testers.

    这篇关于NSMetadataQuery找不到NSFileWrapper文件夹包,只有文件(但他们在那里)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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