配对适用于wifi,但不适用于3g

时间:2014-01-21 19:15:42

标签: ios iphone objective-c game-center gkmatchmaker

出于某种原因,游戏中心matchMaking在同一个wifi上的两个设备上运行良好,但当其中一个设备在3g上时(设备不断搜索并且找不到对方)不能正常工作。 我在用: 1.带有iOS 7.0.4的iPad 2和沙箱帐户(与设备的应用程序商店帐户兼容) 2.带有沙盒帐户的iOS 7.0.4的Iphone 4s(与设备的应用程序商店帐户兼容,但与iPad帐户不同)。

创建匹配的代码如下:

- (IBAction)continueButtonPressed:(id)sender {
GKMatchRequest *request = [[GKMatchRequest alloc] init];
request.minPlayers = 2;
request.maxPlayers = 4;
request.defaultNumberOfPlayers = 2;
if(([[self.gameTypeSegmentControl objectAtIndex:0] selectedSegmentIndex] == 0) ||
   ([[self.gameTypeSegmentControl objectAtIndex:1] selectedSegmentIndex] == 0))
{
    int temp = [self.allLanguages indexOfObject:[[self.languages objectAtIndex:selectedRow] primaryLanguage]];
    if ((temp > 0) && (temp <= self.allLanguages.count))
    {
        request.playerGroup = temp;
    }else
    {
        request.playerGroup = ENGLISH_US_LANG;//50
    }
}
if(([[self.gameTypeSegmentControl objectAtIndex:0] selectedSegmentIndex] == 1) ||
   ([[self.gameTypeSegmentControl objectAtIndex:1] selectedSegmentIndex] == 1))
{
    request.playerGroup = 255;
}

if (isJoining)// Not the creator of the game
{
    request.playerAttributes = JOIN_ATTRIBUTE;
    [[GKMatchmaker sharedMatchmaker] findMatchForRequest:request withCompletionHandler:^(GKMatch *match, NSError *error) {
        if (error)
        {
            NSLog(@"findMatchForRequest ended with error");
            // Process the error.
        }
        else if (match != nil)
        {
            self.myMatch = match; // Use a retaining property to retain the match.
            match.delegate = self;
            if (!self.matchStarted && match.expectedPlayerCount == 0)
            {
                self.matchStarted = YES;
                NSLog(@"match begin");
                // Insert game-specific code to begin the match.
            }
        }
    }];
}else //The creator of the game
{
    request.playerAttributes = CREATE_ATTRIBUTE;
    GKMatchmakerViewController *mmvc = [[GKMatchmakerViewController alloc] initWithMatchRequest:request];
    mmvc.matchmakerDelegate = self;

    [self presentViewController:mmvc animated:YES completion:nil];
}    

}

知道导致问题的原因???

0 个答案:

没有答案