将成就发送到 GameCenter 问题!
好吧,我已经注册了排行榜和成就(仅用于测试目的)。我使用 GameCenterManager.h/.m 和 AppScoreValue.h
我的排行榜正常工作,接收所有分数,将它们按顺序排列,但成就不会授予玩家。
我想要一个显示如何报告成就的示例,我尝试了以下方法:
我的视图确实加载方法如下所示:
-(void)viewDidLoad{
[GKAchievement loadAchievementsWithCompletionHandler:^(NSArray *achievements, NSError *error) {
if (error != nil)
{
NSLog(@"ACHIEVEMENTS WERE NOT LOADED");
} else {
NSLog(@"ACHIEVEMENTS WERE LOADED");
}
if (achievements != nil)
{
NSLog(@"THERE ARE ACHIVEMENTS");
} else {
NSLog(@"THERE ARE NO ACHIVEMENTS %@", achievements);
}
}];
这是我的成就报告方法:
- (IBAction)reportAchievementIdentifier:(NSString*)identifier percentComplete:(float) percent {
GKAchievement *achievement = [[[GKAchievement alloc] initWithIdentifier: identifier] autorelease];
if (achievement)
{
achievement.percentComplete = percent;
[achievement reportAchievementWithCompletionHandler:^(NSError *error)
{
if (error != nil)
{
// Retain the achievement object and try again later (not shown).
}
}];
}
}
Well, I have already registered a leaderboard and an achievement (just for testing purposes). I use that GameCenterManager.h/.m and AppScoreValue.h
My leaderboard is working normally receives all the scores, puts them in order, but the achievement isn't granted to the player.
I'd like an example showing how to report achievements, I tried this:
My view did load method looks like this:
-(void)viewDidLoad{
[GKAchievement loadAchievementsWithCompletionHandler:^(NSArray *achievements, NSError *error) {
if (error != nil)
{
NSLog(@"ACHIEVEMENTS WERE NOT LOADED");
} else {
NSLog(@"ACHIEVEMENTS WERE LOADED");
}
if (achievements != nil)
{
NSLog(@"THERE ARE ACHIVEMENTS");
} else {
NSLog(@"THERE ARE NO ACHIVEMENTS %@", achievements);
}
}];
Here's my achievement reporting method:
- (IBAction)reportAchievementIdentifier:(NSString*)identifier percentComplete:(float) percent {
GKAchievement *achievement = [[[GKAchievement alloc] initWithIdentifier: identifier] autorelease];
if (achievement)
{
achievement.percentComplete = percent;
[achievement reportAchievementWithCompletionHandler:^(NSError *error)
{
if (error != nil)
{
// Retain the achievement object and try again later (not shown).
}
}];
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当您报告成就时,您可以这样调用:(
您希望将标识符替换为您用于 Game Center 标识符的内容。)
我建议查看 此文档,来自 Apple。它包含有关如何在应用程序中使用成就的完整教程。
基本思想是您的应用程序报告用户完成成就的百分比。请注意,成就并不总是立即传播。
When you report an Achievement, you call something like this:
(You want to replace the identifier with whatever you used for your Game Center identifier.)
I suggest looking at this documentation from Apple. It contains a full fledged tutorial on how to use Achievements in your app.
The basic idea is that your app reports a a percentage of how much your user completed the achievement. Note that achievements don't always propagate immediately.
就是这样!
that's it!