views:

31

answers:

1

Apple states that if you want to report a GKAchievement but you get a network error, the best way to handle this is to save the GKAchievement (possibly adding it to an array), then periodically attempt to report the achievement.

What is the best place to save the achievements? Would NSUserDefaults suffice, or would a property list be a better way?

When and how often should I attempt to report? On application launch, or something like every 10 minutes?

+1  A: 

A property list can only handle specific classes (see "What is a Property List?"), which GKAchievement is not one of. NSUserDefaults uses property lists, so that's also out. GKAchievement does, however, conform to the NSCoding protocol, which means you can easily save them to disk using an NSKeyedArchiver. I would create an array of unreported achievements and read/write them like so:

//Assuming these exist
NSArray * unreportedAchievements;
NSString * savePath;

// Write to disk
[NSKeyedArchiver archiveRootObject:unreportedAchievements toFile:savePath];

// Read from disk
unreportedAchievements = [NSKeyedUnarchiver unarchiveObjectWithFile:savePath];
Cory Kilger