Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

removeWithCompletionHandler Error [closed]

Upon start up, I am trying to clear all the matches on the game centre servers between my devices programatically by calling this method on each device:

/**
 *  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.");
}

However, the method does not work, and instead I am greeted with this error in the console:

2012-11-05 08:32:39.699 Spinning Yarn[6266:907] Error removing match: Error Domain=GKErrorDomain Code=17 "The requested operations could not be completed because one or more parameters are invalid." UserInfo=0x1e5b2140 {NSLocalizedDescription=The requested operations could not be completed because one or more parameters are invalid.}

The only error that is happening is inside of the removeWithCompletionHandler: Everything else is fine, and there are no errors.

Any help would be awesome.

like image 402
Infinity James Avatar asked Nov 05 '12 08:11

Infinity James


1 Answers

From the reference for removeWithCompletionHandler:

It is a programming error to call this method on a match that has the local player as an active participant.

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

You are not checking to ensure that the Match is suitable for removal. You may have to end the match for the user before "removing" it. Furthermore, this method is typically meant for users to delete games by choice, not automatically.

like image 146
Saltymule Avatar answered Oct 09 '22 23:10

Saltymule