游戏中心未在iOS 5中显示

时间:2012-05-19 13:32:15

标签: objective-c ios ios5

我使用本教程访问GameCenter。 http://www.raywenderlich.com/3276/how-to-make-a-simple-multiplayer-game-with-game-center-tutorial-part-12 我可以在游戏中心,但如果我想使用这个代码:

 SFAppDelegate * delegate = (SFAppDelegate *) [UIApplication sharedApplication].delegate;                
    [[GCHelper sharedInstance] findMatchWithMinPlayers:2 maxPlayers:2 viewController:self delegate:self];

此代码应该可以使用,但是如果我打电话给它,它只会在上面显示带有蓝色工具栏的黑色屏幕。 这里的“self”是UIViewController,这个控制器实现了GCHelper委托方法。

方法find ...看起来像这样:

- (void)findMatchWithMinPlayers:(int)minPlayers maxPlayers:(int)maxPlayers viewController:(UIViewController *)viewController delegate:(id<GCHelperDelegate>)theDelegate {

    if (!gameCenterAvailable) return;

    matchStarted = NO;
    self.match = nil;
    self.presentingViewController = viewController; // ?
    delegate = theDelegate;               
    [presentingViewController dismissModalViewControllerAnimated:NO];


    if (pendingInvite != nil) 
    {   
        [presentingViewController dismissModalViewControllerAnimated:NO];
        GKMatchmakerViewController *mmvc = [[[GKMatchmakerViewController alloc] initWithInvite:pendingInvite] autorelease];
        mmvc.matchmakerDelegate = self;
        [presentingViewController presentModalViewController:mmvc animated:YES];

        self.pendingInvite = nil;
        self.pendingPlayersToInvite = nil;
    }
    else 
    {   
        [presentingViewController dismissModalViewControllerAnimated:NO];
        GKMatchRequest *request = [[[GKMatchRequest alloc] init] autorelease]; 
        request.minPlayers = minPlayers;     
        request.maxPlayers = maxPlayers;
        request.playersToInvite = pendingPlayersToInvite;

        GKMatchmakerViewController *mmvc = [[[GKMatchmakerViewController alloc] initWithMatchRequest:request] autorelease];    
        mmvc.matchmakerDelegate = self;

        [presentingViewController presentModalViewController:mmvc animated:YES];

        self.pendingInvite = nil;
        self.pendingPlayersToInvite = nil;
    }
}

我不知道我做错了什么.... 感谢您提出任何纠正建议。 :)

0 个答案:

没有答案