Hello, I have been working through some code and I would like to work out how to get around this problem with the GameCenter GameKit.
There is some example code (now open to the public, no longer pre-release so I can talk about it).
@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
}
As you can see above, there is a "Completion Handler" and basically, I want to be able to take data from the completion handler and store it while I run some animations. For example, fade out current data and then fade in new data that was returned from the completion handler. But it doesn't let me.
I try to store the information in an NSArray (NSDictionary in the actual code), but when I call the keys from another function the information is blank.
Any ideas how to get round this?