GKAchievement with partial completion not saving to Game Center (Sandbox)
I'm trying to save partial progress on an achievement and then load it
back when the game starts again. One of my achievements is to do something
1000 times, so I'm submitting a completion number of, say 0.5 for doing it
5 times. But when I quit the game, start it again, and load achievements
from Game Center, the partially completed achievement doesn't come back at
all!
Of note, I have another achievement that works properly, which goes
straight from 0.0 to 100.0 percent complete--and that saved and loaded
back properly the first time I tried it.
Here are my save and load methods:
// _queuedAchievements is a NSMutableSet with GKAchievements in it
- (void) reportQueuedAcheivements
{
NSArray *achievements = [_queuedAchievements allObjects];
if (achievements.count <= 0) {
return;
} else {
NSLog(@"Reporting queued achievements..."); for (GKAchievement *a
in _queuedAchievements) NSLog(@"Achievement: %@, completion:
%.1f", a.identifier, a.percentComplete);
[GKAchievement reportAchievements: achievements
withCompletionHandler:^(NSError *error)
{
if (error != nil)
{
NSLog(@"Error in reporting achievements: %@", error);
} else {
NSLog(@"Successfully reported achievements!");
[_queuedAchievements removeAllObjects];
}
}];
}
}
and...
// _achievementsDictionary is a NSMutableDictionary, as suggesting in
Apple's Game Center guide
- (void) loadAchievements
{
[GKAchievement loadAchievementsWithCompletionHandler:^(NSArray
*achievements, NSError *error) {
NSLog(@"loadAchievements completionHandler called!");
if (error != nil)
{
// Handle the error.
NSLog(@"Error loading achievements: %@", error);
}
if (achievements != nil)
{
NSLog(@"Loaded Achievements...");
for (GKAchievement* achievement in achievements) {
[_achievementsDictionary setObject: achievement forKey:
achievement.identifier];
NSLog(@"%@: %.1f", achievement.identifier,
achievement.percentComplete);
}
}
}];
}
Again, setting an achievement straight to 100.0 works fine, but my partial
value never seems to store. The achievement doesn't show up as paritially
complete in the GameCenter app/view controller either (shouldn't it? I'm
not certain).
This is currently in the Sandbox, so it could be something related to
that, but I doubt it. Is it not permitted to report a completion less than
1.0? I haven't actually tried it yet with >= 1.0, but why have a float if
you can't report a fraction?
(Bonus question...it seems Apple's docs recently changed the information
about storing failed submissions--e.g. when the network is down--and
trying again later, i.e. GameKit does that for you now...anyone know when
this changed?)
No comments:
Post a Comment