关于gamecenter + ios的问题

时间:2012-09-28 13:37:41

标签: iphone ios game-center

我对gamecentre一无所知。我正在研究COCO应用程序 我已经完成gamecenter guide并能够将游戏中心集成到我的应用程序中。

1) 现在,我可以通过我的应用程序在游戏中心输入分数。 通过这样做: -

- (void) reportScore: (int64_t) score forCategory: (NSString*) category 
{
    GKScore *scoreReporter = [[[GKScore alloc] initWithCategory:category] autorelease]; 
    scoreReporter.value = score;
    [scoreReporter reportScoreWithCompletionHandler: ^(NSError *error) 
     {
         [self callDelegateOnMainThread: @selector(scoreReported:) withArg: NULL error: error];
     }];
}

我昨天工作正常。但是现在如果我试图更新分数它没有更新。请任何人知道游戏中心没有更新分数的原因 我试图搜索但没有得到任何东西。

2)我想发送当前纬度&一个玩家到另一个玩家的经度。     我开始知道GKMATCH可以

GKMatchRequest *request = [[[GKMatchRequest alloc] init] autorelease];
    request.minPlayers = 1;
    request.maxPlayers = 1;

    [[GKMatchmaker sharedMatchmaker] findMatchForRequest:request
                                   withCompletionHandler:^(GKMatch *match, NSError *error) {
                                       if (error || !match) {
                                           // handle the error
                                       }
                                       else if (match != nil){
                                           // match found
                                       }}];

    /*GKMatchRequest *request = [[[GKMatchRequest alloc] init] autorelease];
    request.minPlayers = 1;
    request.maxPlayers = 1;
    GKMatchmakerViewController *mmvc = [[GKMatchmakerViewController alloc] initWithMatchRequest:request];
    mmvc.matchmakerDelegate = self;
    currentMatch.delegate=self;
    [self presentModalViewController:mmvc animated:YES];*/
    //[mmvc release];
}
- (void)match:(GKMatch *)match player:(NSString *)playerID didChangeState:(GKPlayerConnectionState)state {
    switch (state){
        case GKPlayerStateConnected: 
            if (match.expectedPlayerCount == 0) {
                // start the match
            }
            break;
        case GKPlayerStateDisconnected:
            // remove the player from the match, notify other players, etc
            break;
    } 
}
- (void)matchmakerViewControllerWasCancelled:(GKMatchmakerViewController *)viewController{}

// Matchmaking has failed with an error
- (void)matchmakerViewController:(GKMatchmakerViewController *)viewController didFailWithError:(NSError *)error{
}


// A peer-to-peer match has been found, the game should start
- (void)matchmakerViewController:(GKMatchmakerViewController *)viewController didFindMatch:(GKMatch *)match{
}

// Players have been found for a server-hosted game, the game should start
- (void)matchmakerViewController:(GKMatchmakerViewController *)viewController didFindPlayers:(NSArray *)playerIDs{
}

// An invited player has accepted a hosted invite.  Apps should connect through the hosting server and then update the player's connected state (using setConnected:forHostedPlayer:)
- (void)matchmakerViewController:(GKMatchmakerViewController *)viewController didReceiveAcceptFromHostedPlayer:(NSString *)playerID {
}
- (void) sendPosition
{
    NSError *error;
    NSString* str = @"teststring";
    NSData* data = [str dataUsingEncoding:NSUTF8StringEncoding];
    //  NSData *packet = [NSData dataWithBytes:&msg length:sizeof(PositionPacket)];
    [currentMatch sendDataToAllPlayers: data withDataMode: GKMatchSendDataUnreliable error:&error];
    if (error != nil)
    {
        // Handle the erro.r
    }
}

但是我不知道为什么但没有调用GKMatchmakerViewController的委托方法我设置了委托但仍然甚至我无法获得GKMATCH(这里是currentMatch)。 所以由于这个原因  [currentMatch sendDataToAllPlayers:data withDataMode:GKMatchSendDataUnreliable error:& error]; 这种方法不起作用。

因为CurrentMatch参考是0X0。 请帮帮我。如何发送和回收数据。 我做错了什么?或者还有别的事要做。

请帮帮我。

谢谢

0 个答案:

没有答案