-
Notifications
You must be signed in to change notification settings - Fork 129
Open
Description
I first try to call
[[GameCenterManager sharedManager] setupManager];
[[GameCenterManager sharedManager] setDelegate:self];
when the app launches. However, the result comes from [self checkGameCenterAvailability] is not correct. Because of the asyn call in localPlayer.authenticateHandler.
I think this will make following code in init method not really useful. Because if GameCenterManager is init when app starts, gameCenterAvailable will always be NO. The essential syncGameCenter call is not called.
if (gameCenterAvailable) {
// Set GameCenter as available
[self setIsGameCenterAvailable:YES];
if (![[NSUserDefaults standardUserDefaults] boolForKey:[@"scoresSynced" stringByAppendingString:[self localPlayerId]]]
|| ![[NSUserDefaults standardUserDefaults] boolForKey:[@"achievementsSynced" stringByAppendingString:[self localPlayerId]]])
[self syncGameCenter];
else
[self reportSavedScoresAndAchievements];
}
I've put a temporary fix as following, everything works fine.
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[[GameCenterManager sharedManager] setupManager];
[[GameCenterManager sharedManager] setDelegate:self];
});
I think checkGameCenterAvailability might be refactor to use completionHandler ?