网络故障后如何保存并重试报告 GKAchievement?
苹果表示,如果你想报告 GKAchievement 但遇到网络错误,处理此问题的最佳方法是保存 GKAchievement(可能将其添加到数组中),然后定期尝试报告成就。
保存成就的最佳位置在哪里? NSUserDefaults 就足够了,还是属性列表是更好的方法?
我应该何时以及多久尝试报告一次?应用程序启动时,还是每隔 10 分钟一次?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
属性列表只能处理特定的类(请参阅 "什么是属性列表?"),
GKAchievement
不是其中之一。NSUserDefaults
使用属性列表,因此这也不再适用。但是,GKAchievement
确实符合NSCoding
协议,这意味着您可以使用NSKeyedArchiver
轻松将它们保存到磁盘。我会创建一系列未报告的成就并像这样读/写它们: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 theNSCoding
protocol, which means you can easily save them to disk using anNSKeyedArchiver
. I would create an array of unreported achievements and read/write them like so:您几乎可以通过将属性列表(以及 NSUserDefaults)中的任何内容转换为 NSData:archivedDataWithRootObject:
You can pretty much save anything in a property list (and thus NSUserDefaults) by turning it into NSData: archivedDataWithRootObject: