Ios5 icloud没有';t更新下载过程
通常,我的代码可以从iCloud下载文件。但有时下载过程不会更新 以下是一些代码片段: 开始下载:Ios5 icloud没有';t更新下载过程,ios5,icloud,icloud-api,Ios5,Icloud,Icloud Api,通常,我的代码可以从iCloud下载文件。但有时下载过程不会更新 以下是一些代码片段: 开始下载: NSFileManager* fm = [NSFileManager defaultManager]; if (![fm startDownloadingUbiquitousItemAtURL:file error:nil]) { return NO; } /////////////////////
NSFileManager* fm = [NSFileManager defaultManager];
if (![fm startDownloadingUbiquitousItemAtURL:file error:nil]) {
return NO;
}
/////////////////////////
id query = [[icloudClass alloc] init];
_query = query;
[query setSearchScopes:[NSArray arrayWithObject:NSMetadataQueryUbiquitousDocumentsScope]];
NSArray *listItems = [[file path] componentsSeparatedByString:@"/"];
NSPredicate *pred = [NSPredicate predicateWithFormat: @"%K == %@", NSMetadataItemFSNameKey, [listItems objectAtIndex:[listItems count] -1] ];
NSLog(@"filename = %@", [listItems objectAtIndex:[listItems count] -1]);
[query setPredicate:pred];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateDownloading:) name:NSMetadataQueryDidUpdateNotification object:query];
[query startQuery];
-(void)updateDownloading:(NSNotification *)notification {
id query = [notification object];
if ([query resultCount] /*>=*/ == 1) {
for (int i=0; i<[query resultCount]; ++i) {
NSMetadataItem *item = [query resultAtIndex:i];
//debug
NSNumber* isDownloading = [item valueForAttribute:NSMetadataUbiquitousItemIsDownloadingKey];
NSNumber* isDownloaded = [item valueForAttribute:NSMetadataUbiquitousItemIsDownloadedKey];
NSNumber* perDownloading = [item valueForAttribute:NSMetadataUbiquitousItemPercentDownloadedKey];
NSLog(@"isDownloaded=%@", [isDownloaded boolValue]?@"Yes":@"No");
NSLog(@"isDownloading=%@", [isDownloading boolValue]?@"Yes":@"No");
NSLog(@"percent downloaded=%f", [perDownloading doubleValue]);
//
if ([isDownloaded boolValue]) {
[query disableUpdates];
[query stopQuery];
[[NSNotificationCenter defaultCenter] removeObserver:self name:NSMetadataQueryDidUpdateNotification object:query];
_query = nil;
NSLog(@"----------end download!------------------");
}
}//end for
}
}
更新下载:
NSFileManager* fm = [NSFileManager defaultManager];
if (![fm startDownloadingUbiquitousItemAtURL:file error:nil]) {
return NO;
}
/////////////////////////
id query = [[icloudClass alloc] init];
_query = query;
[query setSearchScopes:[NSArray arrayWithObject:NSMetadataQueryUbiquitousDocumentsScope]];
NSArray *listItems = [[file path] componentsSeparatedByString:@"/"];
NSPredicate *pred = [NSPredicate predicateWithFormat: @"%K == %@", NSMetadataItemFSNameKey, [listItems objectAtIndex:[listItems count] -1] ];
NSLog(@"filename = %@", [listItems objectAtIndex:[listItems count] -1]);
[query setPredicate:pred];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateDownloading:) name:NSMetadataQueryDidUpdateNotification object:query];
[query startQuery];
-(void)updateDownloading:(NSNotification *)notification {
id query = [notification object];
if ([query resultCount] /*>=*/ == 1) {
for (int i=0; i<[query resultCount]; ++i) {
NSMetadataItem *item = [query resultAtIndex:i];
//debug
NSNumber* isDownloading = [item valueForAttribute:NSMetadataUbiquitousItemIsDownloadingKey];
NSNumber* isDownloaded = [item valueForAttribute:NSMetadataUbiquitousItemIsDownloadedKey];
NSNumber* perDownloading = [item valueForAttribute:NSMetadataUbiquitousItemPercentDownloadedKey];
NSLog(@"isDownloaded=%@", [isDownloaded boolValue]?@"Yes":@"No");
NSLog(@"isDownloading=%@", [isDownloading boolValue]?@"Yes":@"No");
NSLog(@"percent downloaded=%f", [perDownloading doubleValue]);
//
if ([isDownloaded boolValue]) {
[query disableUpdates];
[query stopQuery];
[[NSNotificationCenter defaultCenter] removeObserver:self name:NSMetadataQueryDidUpdateNotification object:query];
_query = nil;
NSLog(@"----------end download!------------------");
}
}//end for
}
}
-(void)updateDownloading:(NSNotification*)通知{
id query=[通知对象];
if([query resultCount]/*>=*/==1){
对于(int i=0;isome)由于网络连接缓慢而发生的情况……但我重新启动应用程序,情况仍然是再次检查此链接如果代码中出现错误,我不会在代码中使用UIDocument,谢谢。你有没有发现这个问题?我在这里看到类似的情况。