【问题标题】:Why isn't startDownloadingUbiquitousItemAtURL:fileURL: starting a download of the item?为什么 startDownloadingUbiquitousItemAtURL:fileURL: 不开始下载项目?
【发布时间】:2012-06-17 14:45:15
【问题描述】:

我正在使用NSMetadataQuery 来检查 iCloud 中的文件。在NSMetadataQueryDidFinishGatheringNotification 处理程序中,如果该项目未下载或未下载,我开始使用startDownloadingUbiquitousItemAtURL:fileURL: 下载它 - 但最近,在两台设备上使用该应用程序后,文档似乎卡住了; startDownloadingUbiquitousItemAtURL:fileURL: 不再启动下载。

这是代码的缩写形式:

    for (NSMetadataItem * result in query.results)
    {   
        NSURL *fileURL = [result valueForAttribute:NSMetadataItemURLKey];

        // snipped: checks that the item isn't hidden or already downloaded

        if (![fileURL getResourceValue:&isDownloading forKey:NSURLUbiquitousItemIsDownloadingKey error:&error] || !isDownloading)
        {
            NSLog(@"Error %@ getting downloading state for item at %@", error, fileURL);
            continue;
        }

        if ([isDownloading boolValue])
        {
            if (![fileURL getResourceValue:&downloadPercent forKey:NSURLUbiquitousItemPercentDownloadedKey error:&error] || !downloadPercent)
            {
                NSLog(@"Error %@ getting downloaded progress for item at %@", error, fileURL);
                continue;
            }

            NSLog(@"Item at %@ has is %@%% downloaded", fileURL, downloadPercent);
        }
        else
        {
            NSLog(@"Starting to download item at %@", fileURL);

            if ([[NSFileManager defaultManager] startDownloadingUbiquitousItemAtURL:fileURL error:&error])
            {
                isDownloading = nil;

                if ([fileURL getResourceValue:&isDownloading forKey:NSURLUbiquitousItemIsDownloadingKey error:&error] && isDownloading)
                {
                    if ([isDownloading boolValue])
                    {
                        NSLog(@"After starting to download, item at %@ is downloading.", fileURL);
                    }
                    else
                    {
                        NSLog(@"After starting to download, item at %@ is still not downloading!", fileURL);
                    }
                }
                else
                {
                    NSLog(@"Error %@ getting downloading state again for item at %@", error, fileURL);
                }
            }
            else
            {
                NSLog(@"Error %@ starting to download item at %@", error, fileURL);
            }
        }
    }

我看到的是:

Starting to download item at XXXXXXXX
After starting to download, item at XXXXXXXX is still not downloading!
Starting to download item at YYYYYYYY
After starting to download, item at YYYYYYYY is still not downloading!
Starting to download item at ZZZZZZZZ
After starting to download, item at ZZZZZZZZ is still not downloading!

为什么 startDownloadingUbiquitousItemAtURL:fileURL: 不开始下载项目?如果是由于某些冲突,我如何检测到该冲突?


更新:我查看了设备控制台,我看到了这个:

MyApp[NNNN] <Warning>: Starting to download item at XXXXXXXX
librariand[MMMM] <Error>: unable to download XXXXXXXX (0x8000000000000000)
MyApp[NNNN] <Warning>After starting to download, item at XXXXXXXX is still not downloading!
MyApp[NNNN] <Warning>Starting to download item at YYYYYYYY
librariand[MMMM] <Error>: unable to download YYYYYYYY (0x8000000000000000)
MyApp[NNNN] <Warning>After starting to download, item at YYYYYYYY is still not downloading!
MyApp[NNNN] <Warning>Starting to download item at ZZZZZZZZ
librariand[MMMM] <Error>: unable to download ZZZZZZZZ (0x8000000000000000)
MyApp[NNNN] <Warning>After starting to download, item at ZZZZZZZZ is still not downloading!

所以看起来至少守护进程被告知下载文件,即使它不能。有没有关于图书馆员错误的文档?

【问题讨论】:

标签: icloud


【解决方案1】:

仔细查看您的NSMetadataQuery 结果中的NSMetadataItem。当您遍历查询请求的结果时,您可以获得以下属性的值:

NSString * const NSMetadataUbiquitousItemIsDownloadedKey;
NSString * const NSMetadataUbiquitousItemIsDownloadingKey;
NSString * const NSMetadataUbiquitousItemIsUploadedKey;
NSString * const NSMetadataUbiquitousItemIsUploadingKey;
NSString * const NSMetadataUbiquitousItemPercentDownloadedKey;
NSString * const NSMetadataUbiquitousItemPercentUploadedKey;

【讨论】:

  • 是的,我知道 - 如果您查看示例代码,我使用 NSURLUbiquitousItemIsDownloadingKey 来查找项目是否正在下载。问题是该事件虽然我已调用 startDownloadingUbiquitousItemAtURL:fileURL:,但该项目仍未下载。
  • 再次。 NSMetadataItem 对象的NSMetadataUbiquitousItemIsDownloadingKey 属性与NSURL 对象的NSURLUbiquitousItemIsDownloadingKey 之间存在差异。前者应该用于 iCloud 元数据查询处理。其他属性相同
  • 我已修改我的应用程序以尽可能使用 valueForAttribute;虽然似乎没有 NSURLIsHiddenKey 的等价物。一旦我重现卡住的状态,我会在这里更新。
  • 我得到一个稍微不同的图书馆管理员错误:“图书馆管理员 [4220] :项目更新观察者错误:连接无效”
  • @simon 您可以在元数据请求构建期间摆脱隐藏元素。这是因为它是元数据信息,而不是实际的文件系统项。您的第二条评论需要更多数据才能得到答复。
猜你喜欢
  • 1970-01-01
  • 2019-03-22
  • 2012-04-03
  • 2021-07-09
  • 1970-01-01
  • 2021-03-06
  • 1970-01-01
  • 2016-08-30
  • 2010-12-20
相关资源
最近更新 更多