首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >iCloud: NSMetadataQuery在删除设置设备中的文件时返回错误的结果

iCloud: NSMetadataQuery在删除设置设备中的文件时返回错误的结果
EN

Stack Overflow用户
提问于 2014-03-26 10:57:56
回答 1查看 350关注 0票数 1
  • 我下载了一首歌->,它是同步在‘`iCloud。
  • 我会将-> iCloud ->管理存储应用程序设置为删除所有文件。
  • 我转到我的应用程序并检查来自(NSMetadataQueryDidFinishGatheringNotification和NSMetadataQueryDidUpdateNotification的通知) -> NSMetadataQuery.results返回1项(旧值)

先谢谢你。

代码语言:javascript
复制
enter code here

    - (void)processiCloudFiles:(NSNotification *)notification {
         [_query disableUpdates];
         [_iCloudNames removeAllObjects];
         int totalItems = _query.resultCount; // it not update here
         //OR: _query.results
    }
    - (void)startQuerying {
         [self stopQuery];
         _query = [self documentQuery];
         [[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(processiCloudFiles:)
                                             name:NSMetadataQueryDidFinishGatheringNotification
                                           object:nil];
         [[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(processiCloudFiles:)
                                             name:NSMetadataQueryDidUpdateNotification
                                           object:nil];
         [_query startQuery];
    }

    - (void)stopQuery {
       if (_query) {
         [[NSNotificationCenter defaultCenter] removeObserver:self name:NSMetadataQueryDidFinishGatheringNotification object:nil];
         [[NSNotificationCenter defaultCenter] removeObserver:self name:NSMetadataQueryDidUpdateNotification object:nil];
         [_query stopQuery];
         _query = nil;
       }
    }

    - (NSMetadataQuery *)documentQuery {
       NSMetadataQuery * query = [[NSMetadataQuery alloc] init];
       if (query) {
          [query setSearchScopes:[NSArray arrayWithObject:NSMetadataQueryUbiquitousDocumentsScope]];        
          NSString * filePattern = [NSString stringWithFormat:@"*.%@", FILE_EXTENSION];
          [query setPredicate:[NSPredicate predicateWithFormat:@"%K LIKE %@",
                         NSMetadataItemFSNameKey, filePattern]];
       }
       return query;
    }
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-04-29 04:18:02

当用户按“主页”按钮时,可以在“文档”文件夹中创建临时文件。这样做是因为用户可能会去设置设备并删除歌曲。

当用户转到应用程序时,您可以删除这个临时文件,以便iCloud可以刷新数据列表。

希望这能帮到你。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22658846

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档