游戏中心分数报告问题
我正在开发一个应用程序,使用下面的代码(按照苹果的建议)向游戏中心报告分数。 我的问题是,即使我的 iPhone 处于飞行模式,该应用程序也不会触发任何分数报告错误。它只是转到代码的“提交确定”部分。 知道为什么吗? 谢谢你!
GKScore *scoreReporter = [[[GKScore alloc] initWithCategory:category] autorelease];
scoreReporter.value = score;
[scoreReporter reportScoreWithCompletionHandler:^(NSError *error) {
if (error != nil)
{
// handle the reporting error
NSLog(@"Error Descr %@",error.localizedDescription);
NSLog(@"Error Code %@",error.code);
NSLog(@"Error Domain %@",error.domain);
}
else {
NSLog(@"Submission ok");
}
}];
I am developing an app that reports a score to Game Center using the code below (as suggested by Apple).
My problem is that even when my iPhone is in Airplane mode, the app does not trigger any score reporting error. It just goes to the "Submission ok" section of the code.
Any idea why?
Thank you!
GKScore *scoreReporter = [[[GKScore alloc] initWithCategory:category] autorelease];
scoreReporter.value = score;
[scoreReporter reportScoreWithCompletionHandler:^(NSError *error) {
if (error != nil)
{
// handle the reporting error
NSLog(@"Error Descr %@",error.localizedDescription);
NSLog(@"Error Code %@",error.code);
NSLog(@"Error Domain %@",error.domain);
}
else {
NSLog(@"Submission ok");
}
}];
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
从 iOS 5.0 开始,由
reportScoreWithCompletionHandler
引起的任何网络错误均由 GameKit 在内部处理。这意味着开发者不必再担心因网络故障而重新提交待处理的分数。如果您使用 iOS 5.0 及更高版本进行构建,则reportScoreWithCompletionHandler
的完成处理程序将不会收到任何与网络相关的错误。Starting with iOS 5.0, any network errors arising out of
reportScoreWithCompletionHandler
are handled internally by GameKit. This means that developers no longer have to worry about resubmitting scores pending due to network failures. If you're building with iOS 5.0 and later, the completion handler ofreportScoreWithCompletionHandler
will not receive any network-related errors.我建议您自己使用 Apple 的可达性标志来检测活动连接。如果连接不可用,请存储您的 Game Center 请求以供将来提交,并在网络再次可用时提交。有关可达性的更多信息,请访问此处
I would suggest using Apple's reachability flags to detect an active connection yourself. If a connection isn't available, store your Game Center requests for future submission and submit them when network becomes available again. More on reachability can be found here