icloud doesn't update the download precess
Asked Answered
D

0

5

Usually, my code is ok to download the files from iCloud. But sometimes the downloading process will not be updated.

Following are some code snips:

start download:

            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];

update download:

    -(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
    } 
}

please note that the update function will only be invoked once with the following console print, and never will be invoked even restart the app.

Jan 10 15:20:27 unknown *[1383] <Warning>: isHasConflict=No
Jan 10 15:20:27 unknown *[1383] <Warning>: isDownloaded=No
Jan 10 15:20:27 unknown *[1383] <Warning>: isDownloading=No
Jan 10 15:20:27 unknown *[1383] <Warning>: percent downloaded=0.000000

Does anyone met this problem before?

Delphadelphi answered 10/1, 2012 at 9:58 Comment(6)
some times it happens due to slow net connectivity......Cristycriswell
but I restart the app, the situation is still onDelphadelphi
check this link if something going wrong in your code https://mcmap.net/q/663460/-uimanageddocument-example-tutorialCristycriswell
I don't use UIDocument in my code though, thanks.Delphadelphi
Did you ever figure this one out? I'm seeing similar here.Disband
I've been having the same problem where some documents refuse to download. It seems to be a bug in iCloud where the local daemon gets confused and does not download files. I've found that I can reset it by turning off iCloud Program Data in Settings, restarting the device and turning iCloud Program Data back on. I had hoped it would be fixed in iOS 6.0, but so far no luck :(Shady

© 2022 - 2024 — McMap. All rights reserved.