iOS' reportAchievementWithCompletionHandler'贬值

时间:2015-09-16 20:10:07

标签: ios objective-c

代码的一部分(我没有写)在我的Xcode项目中显示为折旧,这里是代码块:

#pragma mark - Report Achievement Progress
static int reportAchievement(struct lua_State *state) {
    [gameCenterAddOnInstance reportAchievementAction:[NSString stringWithCString:lua_tostring(state, 1) encoding:NSUTF8StringEncoding] percentComplete:(int)lua_tointeger(state, 2)];

    return 1;
}

- (void) reportAchievementAction: (NSString*) identifier percentComplete: (float) percent
{
    GKAchievement *achievement = [[GKAchievement alloc] initWithIdentifier: identifier];
    if (achievement)
    {
        achievement.percentComplete = percent;
        [achievement reportAchievementWithCompletionHandler:^(NSError *error)
         {
             if (error != nil)
             {
                 NSLog(@"Error in reporting achievements: %@", error);
             }
         }];
    }
}

根据Xcode,折旧部分是:

reportAchievementWithCompletionHandler

Xcode建议使用:

reportAchievements:WithCompletionHandler:

相反。但是,不熟悉目标C,我不知道从哪里开始。

如何实现新功能? 非常感谢任何帮助。

1 个答案:

答案 0 :(得分:1)

试试这个

[GKAchievement reportAchievements:@[achievement] withCompletionHandler:^(NSError *error)
     {
         if (error != nil)
         {
             NSLog(@"Error in reporting achievements: %@", error);
         }
     }];

Apple使用类方法- reportAchievementWithCompletionHandler:替换了实例方法+ reportAchievements:withCompletionHandler:。这允许您一次报告多个成就,而无需在每个成就对象上调用实例方法。

@[achievement][NSArray arrayWithObjects:achievement, nil]的缩写。