Я работал над некоторым кодом, и я хотел бы разобраться, как обойти эту проблему с GameCenter GameKit.Внешние данные с CompletionHandler не работают
Существует некоторый пример кода (теперь открытый для публики, более не предварительный выпуск, поэтому я могу поговорить об этом).
@synthesize playerStorage;
- (void)loadPlayerData:(NSArray *)identifiers
{
[GKPlayer loadPlayersForIdentifiers:identifiers withCompletionHandler:^(NSArray *players, NSError *error) {
if (error != nil
{
// Handle the error.
}
if (players != nil)
{
// Process the array of GKPlayer objects.
// If I put this array in one I have created for the ViewController
// it doesn't actually store it. It's like it can't find it.
// But it doesn't error.
[self setPlayerStorage:players];
// Then animate to show why I need to do it this way, I cannot pass data
[UIView beginAnimations:@"fadeInPlayer" context:self];
[UIView setAnimationDuration:1.0];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(fadeInFriend:finished:context:)];
labelPlayer.alpha = 0.0;
[UIView commitAnimations];
}
}];
}
- (void)fadeInFriend:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context
{
// Try and get the contents of playerStorage and update the label
labelPlayer.text = [[playerStorage objectAtIndex:0] alias];
// Fade in player label but label is blank
// This is all example data, I'm doing it differently in the actual app
}
Как вы можете видеть выше, есть «Завершение Handler» и в принципе, я хочу, чтобы иметь возможность принимать данные из обработчика завершения и сохранить его, пока я сбегаю некоторые анимации. Например, затухают текущие данные и затем исчезают в новых данных, которые были возвращены обработчиком завершения. Но это не позволяет мне.
Я пытаюсь сохранить информацию в NSArray (NSDictionary в фактическом коде), но когда я вызываю ключи от другой функции, информация пуста.
Любые идеи, как обойти это?