iphone - Wait until GameCenter score download id complete -
i download score gamecenter, don't know how wait, when score downloaded. when run code, returns null. think, method have wait when [leaderboardrequest loadscoreswithcompletionhandler: ...
have score downloaded.
- (nsstring*) getscore: (nsstring*) leaderboardid { __block nsstring *score = nil; gkleaderboard *leaderboardrequest = [[gkleaderboard alloc] init]; if (leaderboardrequest != nil) { leaderboardrequest.identifier = leaderboardid; [leaderboardrequest loadscoreswithcompletionhandler: ^(nsarray *scores, nserror *error) { if (error != nil) { nslog(@"%@", [error localizeddescription]); } if (scores != nil) { int64_t scoreint = leaderboardrequest.localplayerscore.value; score = [nsstring stringwithformat:@"%lld", scoreint]; } }]; } return score; }
the code completion handler called when operation complete (on thread).
you have several options there, can store score somewhere , post notification notify main thread operation completed.
Comments
Post a Comment