【问题标题】:Load iCloud document from subFolder in iOS从 iOS 中的子文件夹加载 iCloud 文档
【发布时间】:2013-09-02 02:56:06
【问题描述】:

我已成功在 iCloud 中创建名为 Note 的文件夹。

我知道从 iCloud 文档目录加载文件的方法。

但我不知道如何从 Notes 文件夹加载。

我只想加载笔记文件夹中的所有文档。不是来自文档目录。

目录路径是这样的:"iCloud>Documents>Notes"

这是我从 iCloud 文档文件夹加载数据的一些代码。

[self.notes removeAllObjects];
    NSMutableArray* tmpFileList = [[NSMutableArray alloc] init];    
    for (NSMetadataItem *item in [query results])
    {
        NSURL *url = [item valueForAttribute:NSMetadataItemURLKey];
        Note *doc = [[Note alloc] initWithFileURL:url];
        doc.lastModDate = [item valueForAttribute:NSMetadataItemFSContentChangeDateKey];
        [tmpFileList addObject:doc];
    }

    NSSortDescriptor *descriptor = [NSSortDescriptor sortDescriptorWithKey:@"lastModDate" ascending:NO];
    self.notes = [NSMutableArray arrayWithArray:[tmpFileList sortedArrayUsingDescriptors:[NSArray arrayWithObject:descriptor]]];

    [self.tblMainTableView reloadData];

如何加载?

【问题讨论】:

    标签: ios icloud nsfilemanager


    【解决方案1】:

    如果您的查询返回所有目录中的文件,您可以过滤掉不在您的 Notes 目录中的文件。使用 [url pathComponents] 之类的东西,看看最后一个文件夹是否是“Notes”。

    话虽如此,听起来您想要更多地控制文件在 iCloud 中的存储方式,因此您可能想要使用 WWDC 2012 会议 237 - 高级 iCloud 文档存储中讨论的“鞋盒”方法。

    【讨论】:

      猜你喜欢
      • 2018-09-18
      • 1970-01-01
      • 2015-08-31
      • 2015-01-19
      • 1970-01-01
      • 2015-10-20
      • 2013-04-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多