我正在尝试以编程方式使用游戏中心创建实时多人游戏。我的问题是缺少文档,因为旧的inviteHandler
已被弃用。
我做的第一件事是身份验证:
- (void) authenticateLocalPlayer
{
GKLocalPlayer *localPlayer = [GKLocalPlayer localPlayer];
__weak GKLocalPlayer *blockLocalPlayer = localPlayer;
localPlayer.authenticateHandler = ^(UIViewController *receivedViewController, NSError *error)
{
if (receivedViewController != nil)
{
[self presentViewController:receivedViewController animated:YES completion:nil];
}
else if (blockLocalPlayer.isAuthenticated)
{
[blockLocalPlayer registerListener:self];
}
};
}
之后,我按照Apple docs上的说法启动邀请流程。
- (void)invitePlayers:(NSArray *)friendsArray
{
GKMatchRequest *request = [[GKMatchRequest alloc] init];
request.minPlayers = 2;
request.maxPlayers = 2;
request.playersToInvite = friendsArray;
request.inviteMessage = @"Your Custom Invitation Message Here";
request.inviteeResponseHandler = ^(NSString *playerID, GKInviteeResponse response)
{
[self updateUIForPlayer: playerID accepted: (response == GKInviteeResponseAccepted)];
};
}
我实现了以下方法,但从不调用它们:
- (void)player:(GKPlayer *)player didAcceptInvite:(GKInvite *)invite
- (void)player:(GKPlayer *)player didRequestMatchWithPlayers:(NSArray *)playerIDsToInvite
如何让其他玩家收到邀请并回复?在苹果文档中,证明了旧的弃用方式。
答案 0 :(得分:0)
尝试首先注册GKLocalPlayer
侦听器,以便通过此方法调用:
- (void)registerListener:(id<GKLocalPlayerListener>)listener
应符合此协议:GKLocalPlayerListener