7

启动时,我试图通过在每个设备上调用此方法以编程方式清除我的设备之间的游戏中心服务器上的所有比赛:

/**
 *  called to authenticate the players game centre id
 */
- (void)authenticateLocalUser
{
    if (!self.gameCentreAvailable)          return;

    NSLog(@"Authenticating Local User.");

    if ([GKLocalPlayer localPlayer].authenticated == NO)
    {
        [[GKLocalPlayer localPlayer] setAuthenticateHandler:^(UIViewController* viewcontroller, NSError *error)
        {
            NSLog(@"Inside Authentication Handler.");

            //  if there was no error, and we got a valid view controller to display
            if (!error && viewcontroller)
            {
                //  get a handle to the app delegate
                AppDelegate *delegate       = [UIApplication sharedApplication].delegate;

                //  use the view controller in the app delegate to present the authentication view controller
                [delegate.viewController presentViewController:viewcontroller animated:YES completion:
                ^{
                    //  once the view controller has been displayed, register the change in authentication
                    [self authenticationChanged];
                }];

                //  set this class as the event handler delegate
                GKTurnBasedEventHandler *event  = [GKTurnBasedEventHandler sharedTurnBasedEventHandler];
                event.delegate                  = self;
            }

            //  load all of the matches the player is currently a part of
            [GKTurnBasedMatch loadMatchesWithCompletionHandler:^(NSArray *matches, NSError *error)
            {
                NSLog(@"Error loading matches: %@", error);

                //  for each match
                for (GKTurnBasedMatch *match in matches)
                {
                    //  log the id of the match
                    NSLog(@"ID of match we are removing: %@", match.matchID);

                    //  and then remove it
                    [match removeWithCompletionHandler:^(NSError *error)
                    {
                        NSLog(@"Error removing match: %@", error);
                    }];
                }
            }];
        }];
    }
    else
        NSLog(@"Already Authenticated.");
}

但是,该方法不起作用,而是在控制台中收到此错误:

2012-11-05 08:32:39.699 纺纱 [6266:907] 删除匹配时出错:错误域 = GKErrorDomain 代码 = 17 “请求的操作无法完成,因为一个或多个参数无效。” UserInfo=0x1e5b2140 {NSLocalizedDescription=请求的操作无法完成,因为一个或多个参数无效。}

发生的唯一错误是在 removeWithCompletionHandler 内部:其他一切都很好,并且没有错误。

任何帮助都是极好的。

4

1 回答 1

4

从 removeWithCompletionHandler 的参考资料中:

在本地玩家作为活跃参与者的比赛上调用此方法是一个编程错误。

http://developer.apple.com/library/ios/#documentation/GameKit/Reference/GKTurnBasedMatch_Ref/Reference/Reference.html

您没有检查以确保匹配适合删除。您可能必须在“删除”之前结束用户的匹配。此外,这种方法通常是为了让用户选择删除游戏,而不是自动删除。

于 2012-11-05T15:43:53.853 回答