iPhone 游戏中心 - 加载成就进度

发布于 2024-10-08 12:19:00 字数 1579 浏览 4 评论 0原文

我让我的应用程序在游戏中心成就实现/达到 100% 时发出通知,但是每次用户完成它时它都会显示通知,但我只希望它在实际完成时第一次通知。

我在苹果文档中找到了这个: http://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/GameKit_Guide/Achievements/Achievements.html#//apple_ref/doc/uid/TP40008304-CH7-SW11

但是不太明白它如何帮助解决我的问题。

我只想在首次实现成就时调用此通知一次。因此,仅在尚未实现时才显示它。

编辑

我有这个来解锁成就:

- (void) 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).
             }
         }];
    }
}

并用这个解锁:

[self reportAchievementIdentifier:identifier percentComplete:percent];

然后用这一行显示通知:

[[GKAchievementHandler defaultHandler] notifyAchievementTitle:@"Title" andMessage:@"Message"];

那么我只需要在该代码块中添加类似的东西吗?

if (achievement.completed != TRUE) {
      [[GKAchievementHandler defaultHandler] notifyAchievementTitle:@"Title" andMessage:@"Message"];
}

I have my app give a notification when a Game Center achievement is achieved/reaches 100%, however it shows the notification every times the user completes it, but I only want it to notify the first time in actually completed.

I found this in the Apple docs:
http://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/GameKit_Guide/Achievements/Achievements.html#//apple_ref/doc/uid/TP40008304-CH7-SW11

However didn't quite understand how it help fix my issue.

I only want to call this notification once, when the achievement is first achieved. So only show it if its not already achieved.

Edit

I have this to unlock the achievement:

- (void) 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).
             }
         }];
    }
}

And unlock with this:

[self reportAchievementIdentifier:identifier percentComplete:percent];

Then show the notification with this line:

[[GKAchievementHandler defaultHandler] notifyAchievementTitle:@"Title" andMessage:@"Message"];

So do I simply need something like this in that code chunk?

if (achievement.completed != TRUE) {
      [[GKAchievementHandler defaultHandler] notifyAchievementTitle:@"Title" andMessage:@"Message"];
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

甜柠檬 2024-10-15 12:19:01

GKAchievement中有一个“已完成”属性...尝试创建一个新的GKAchievement并检查它是否未完成,然后解锁它。

There's a "completed"-property in GKAchievement... Try to make a new GKAchievement and check if it's not completed, then unlock it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文