How to save and retry GKAchievement report after network failure?

Apple claims that if you want to report GKAchievement, but you get a network error, the best way to deal with this is to save GKAchievement (perhaps by adding it to the array), and then periodically try to report the achievement.

What is the best place to preserve achievements? Will NSUserDefaults suffice or is the property list better?

When and how often should I try to report? When you start the application or something like every 10 minutes?

+4
source share
2 answers

A property list can only process certain classes (see What is a property list? ), Which GKAchievement not one of, NSUserDefaults uses property lists, so do that. GKAchievement , however, complies with the NSCoding protocol, which means that you can easily save them to disk using NSKeyedArchiver . I would create an array of unregistered achievements and read / write them like this:

 //Assuming these exist NSArray * unreportedAchievements; NSString * savePath; // Write to disk [NSKeyedArchiver archiveRootObject:unreportedAchievements toFile:savePath]; // Read from disk unreportedAchievements = [NSKeyedUnarchiver unarchiveObjectWithFile:savePath]; 
+5
source

You can pretty much save something in the property list (and therefore NSUserDefaults) by turning it into NSData: archivedDataWithRootObject:

0
source

All Articles