- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
对于我的游戏的在线模式,我正在使用context
的GKScore
属性,并且由于所有支持Game Center的设备都可以更新到iOS 5(这是在添加context
属性时),因此我要求context
属性可用在线玩。但是,在执行此运行时检查时遇到问题。我以为可以使用[GKScore instancesRespondToSelector:@selector(setContext:)]
来检查它的存在,但是在iOS 5和5.1模拟器以及@selector(context)
上,它返回false。为什么这会发生,请问执行此检查的最干净正确的方法是什么?
最佳答案
我无法完全解释这一点,但是GKScore
类的实例化对象会将 YES 返回给repondsToSelector(context)
,即使该类说不会。如果没有其他解决方案,请构造一个GKScore
对象以进行查询。
我想知道[[GKScore alloc] init]
是否实际上返回GKScore
以外类型的对象。这可能发生。
GKScore *instantiatedScore = [[GKScore alloc] init]; // Add autorelease if using manual reference counting.
NSString* className = NSStringFromClass([instantiatedScore class]);
NSLog(@"instantiatedScore class name = %@", className);
instantiatedScore class name = GKScore
GKSCore.h
头文件中的编译器指令是否会影响这一点。它定义了两个仅在iOS 5.0或更高版本中可用的属性:
context
和
shouldSetDefaultLeaderboard
。也许那些编译器指令意味着该类不能保证它将支持这两个属性。
[GKScore instancesRepondToSelector:@selector(category)]
应该返回
是,但是
[GKScore instancesRepondToSelector:@selector(shouldSetDefaultLeaderboard)]
应该返回
NO 。
GKScore *instantiatedScore = [[GKScore alloc] init]; // Add autorelease if using manual reference counting.
NSLog(@"GKScore category = %d", [GKScore instancesRespondToSelector:@selector(category)]);
NSLog(@"instantiatedScore category = %d", [instantiatedScore respondsToSelector:@selector(category)]);
NSLog(@"GKScore context = %d", [GKScore instancesRespondToSelector:@selector(context)]);
NSLog(@"instantiatedScore context = %d", [instantiatedScore respondsToSelector:@selector(context)]);
NSLog(@"GKScore shouldSetDefaultLeaderboard = %d", [GKScore instancesRespondToSelector:@selector(shouldSetDefaultLeaderboard)]);
NSLog(@"instantiatedScore shouldSetDefaultLeaderboard = %d", [instantiatedScore respondsToSelector:@selector(shouldSetDefaultLeaderboard)]);
GKScore category = 0
instantiatedScore category = 1
GKScore context = 0
instantiatedScore context = 1
GKScore shouldSetDefaultLeaderboard = 1
instantiatedScore shouldSetDefaultLeaderboard = 1
关于objective-c - 检查GKScore实例是否具有上下文属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12126501/
我有时遇到 SIGABRT 崩溃,崩溃提示:GKScore 必须包含初始化值。 所以它追踪到这一行: [localScore reportScoreWithCompletionHandler:^(NS
在苹果的 GKLeaderboards示例代码,它们展示了如何存储 GKScore 对象,以便在发送失败时稍后提交。但是,Reporting Scores To Game Center 的文档说“如果
当我尝试存储小于当前值的分数值时,它不会被存储。有什么帮助吗? GKScore *scoreReporter = [[GKScore alloc] initWithCategory:@"top_mat
有人在尝试将 Game Center 集成到 iOS 7 应用程序时遇到过这个错误吗? A GKScore must specify a leaderboard. 这是失败的代码: if(points
我对 iOS 中与“游戏中心”相关的主题有疑问:GKAchievement 与 GKScore? (1) GK成就 我知道在 iOS Game Center 中,我们可以定义成就和排行榜并指定,例如,
谁能告诉我如何使用 C# 编写 ReportScores 示例?我发现了很多关于它是如何用 objective-C 而不是 C# 编写的例子,而且转换器很贵。我一直在使用旧的、现在已弃用的 GKSco
让 highscore = leaderboardRequest.scores[0] 为! GKScore 结果为 无法下标“[GKScore]”类型的值? Swift2 中正确的语法是什么 最佳答案
我是一名优秀的程序员,十分优秀!