我有一個塊正在檢查用戶從firebase中的狀態屬性。如果狀態屬性是「自由」我想從塊返回,否則我想搜索其他用戶,並檢查他們的身份和這樣做,直到一個「自由」的用戶已經發現:一個塊內的塊被調用後出現不良訪問(iOS)
void(^ myResponseBlock)(BOOL finished) =^void(BOOL finished) {
if (finished) {
if ([self.freedom isEqualToString: @"free"]) {
NSLog(@"free!");
return;
} else if ([self.freedom isEqualToString: @"matched"]) {
NSLog(@"get another user");
//get another user
do {
//picking another random user from array
rando = arc4random_uniform(arraycount);
}
while (rando == randomIndex && rando == [self.randString intValue]);
self.randString = [NSString stringWithFormat: @"%u", rando];
[users removeAllObjects];
[users addObject:usersArray[rando]];
self.freeUser = users.firstObject;
NSLog(@"set up another check");
//error is called after this block is called here, again
[self checkIfFree: myResponseBlock];
} else {
NSLog(@"error!");
}
} else {
NSLog(@"not finished the checking yet");
}
};
[self checkIfFree: myResponseBlock];
如圖所示,我得到「錯誤訪問」的錯誤時,調用塊在第二次「compblock(YES)」低於行:
-(void)checkIfFree:(myCompletion) compblock{
self.freeUserFB = [[Firebase alloc] initWithUrl:[NSString stringWithFormat: @"https://skipchat.firebaseio.com/users/%@", self.freeUser.objectId]];
[self.freeUserFB observeEventType:FEventTypeValue withBlock:^(FDataSnapshot *snapshot)
{
self.otherStatus = snapshot.value[@"status"];
NSLog(@"snapshot info %@", snapshot.value);
if ([self.otherStatus isEqualToString:@"free"]) {
self.userIsFree = YES;
self.freedom = @"free";
NSLog(@"user is free in the check method %@", self.freedom);
}
else{
self.userIsFree = NO;
self.freedom = @"matched";
NSLog(@"user is matched in the check method %@", self.freedom);
}
compblock(YES);
}];
}
一切都很好,如果塊沒有被被召回並且被檢查的第一個用戶已經是「免費」的。我被困在爲什麼我得到這個錯誤/崩潰,並想知道我能如何解決它!
謝謝!
在checkIfFree中複製comp塊: – malex 2015-02-07 23:24:02
我該怎麼做? – ryder 2015-02-07 23:27:20
myCompletion copyBlock = [compblock copy]; – malex 2015-02-07 23:29:59