I started with the friendsmash Facebook example and getting a score does not work if no score has previously been set. The code is below. If this is called it simply stalls at FBRequestConnection and does not produce an error or any result, no further code is executed in the block. Obviously this is unacceptable.
If I post the score without first checking its value, it posts fine, and then I can check its value correctly. I assume the call is not supposed to 'hang' if no score is set at all, or should I just not check the score and always post it?
void FB_Controller::FB_SendScore(const int nScore)
{
// Make sure we have write permissions
FB_RequestWritePermissions();
NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
[NSString stringWithFormat:@"%d", nScore], @"score",
nil];
NSLog(@"Fetching current score");
// Get the score, and only send the updated score if it's highter
[FBRequestConnection startWithGraphPath:[NSString stringWithFormat:@"%llu/scores", m_uPlayerFBID] parameters:params HTTPMethod:@"GET" completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
if(error)
{
NSLog(@"ERROR getting score %@", error);
}
else if (result && !error) {
int nCurrentScore = [[[[result objectForKey:@"data"] objectAtIndex:0] objectForKey:@"score"] intValue];
NSLog(@"Current score is %d", nCurrentScore);
if (nScore > nCurrentScore) {
NSLog(@"Posting new score of %d", nScore);
[FBRequestConnection startWithGraphPath:[NSString stringWithFormat:@"%llu/scores", m_uPlayerFBID] parameters:params HTTPMethod:@"POST" completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
if(error)
{
NSLog(@"ERROR posting score %@", error);
}
else
NSLog(@"Score posted");
}];
}
else {
NSLog(@"Existing score is higher - not posting new score");
}
}
}];
// Send our custom OG
//FB_SendOG();
}