lundi 29 juin 2015

CKQueryOperation use with initWithCursor


What am I missing here; I got 125 records on the database, but when I run this I get the same set twice, so initWithCursor doesn't work? Must have done something wrong? missed an important detail here?

-(void)loadStudentControls1n2Picker
{
 __block NSMutableArray *students2load = [[NSMutableArray alloc] init];

    CKDatabase *publicDatabase = [[CKContainer containerWithIdentifier:@"iCloud.blah"] publicCloudDatabase];

    NSPredicate *predicatex = nil;
    predicatex = [NSPredicate predicateWithFormat:@"iBeaconConfig = %@", iBeaconsConfirmed.giReferenceID];
    CKQuery *query = [[CKQuery alloc] initWithRecordType:@"SingleBeaconsDB" predicate:predicatex];
    CKQueryOperation *queryOp =[[CKQueryOperation alloc] initWithQuery:query];
    queryOp.desiredKeys = @[@"record.recordID.recordName",@"Owner"];

    queryOp.recordFetchedBlock = ^(CKRecord *results)
    {
    NSLog(@"Finds ...  %@",results.recordID.recordName);
    if (results[@"Owner"] != nil) {
        [students2load addObject:results[@"Owner"]];
    }
    [iBeaconSingleConfirmed addObject:results];
};

queryOp.queryCompletionBlock = ^(CKQueryCursor *cursor, NSError *error)
{
    NSLog(@"students2load  %lu ", (unsigned long)[students2load count]);

    if (cursor != nil) {
        CKQueryOperation *queryOp2 = [[CKQueryOperation alloc] initWithCursor:cursor];
        queryOp2.desiredKeys = @[@"record.recordID.recordName",@"Owner"];
        queryOp2.recordFetchedBlock = ^(CKRecord *results)
        {
            NSLog(@"Finds ...  %@",results.recordID.recordName);
            if (results[@"Owner"] != nil) {
                [students2load addObject:results[@"Owner"]];
            }
            [iBeaconSingleConfirmed addObject:results];
        };
        queryOp2.queryCompletionBlock = ^(CKQueryCursor *cursor, NSError *error)
        {
            NSLog(@"students2load  %lu ", (unsigned long)[students2load count]);
            [globalPickerConfirmed uploadArray2Picker:students2load];
        };
        [publicDatabase addOperation:queryOp2];
    }


    [self.delegate performSelectorOnMainThread:@selector(refreshPicker:)  withObject:@"Teacher" waitUntilDone:YES];
};

[publicDatabase addOperation:queryOp];
}

I end up with 190 records which is the same set of 95 records x 2.


Aucun commentaire:

Enregistrer un commentaire