为什么不startDownloadingUbiquitousItemAtURL:fileURL:开始下载项目?

时间:2012-06-14 14:29:15

标签: icloud

我正在使用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!

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

1 个答案:

答案 0 :(得分:2)

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

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