问题描述
我很难邀请一位朋友参加比赛.
GKMatchRequest *request = [[[GKMatchRequest alloc] init] autorelease];
request.minPlayers = 2;
request.maxPlayers = 2;
request.playersToInvite = [NSArray arrayWithObjects: @"G:1102359306",nil ];
// GKMatchmakerViewController *mv = [[GKMatchmakerViewController alloc] initWithMatchRequest:request];
// [self presentModalViewController:mv animated:YES];
[[GKMatchmaker sharedMatchmaker] findMatchForRequest:request withCompletionHandler:^(GKMatch *match, NSError *error) {
if (error) {
NSLog([error description]);
}
else if (match != nil) {NSLog(@"good match");
//self.chatMatch = match;
//self.chatMatch.delegate = self;
//[self chatReady];
}
else {
NSLog(@"other error");
}
}];
问题是我从未在登录到该帐户的第二台设备上收到邀请通知-G:1102359306.当我使用GKMatchmakerViewController(在2行以上未注释)并注释GKMatchmaker块时,我自动检查了好朋友-G:1102359306,当我邀请他时显示了带有接受/拒绝的通知,这就是我所知的正确方法.
您发现上面的代码有什么问题吗?我想使用自己的UI来处理多人游戏模式.奇怪的问题是,在控制台中我也看不到任何匹配或其他错误的日志,并且仅当我两次调用上述代码时才显示[错误描述]-它表示先前的要求已被取消.
您不能以编程方式邀请一组特定的球员参加比赛. findMatchForRequest:withCompletionHandler:
文档这样说:
没有公共API可以满足您的要求.
I'm facing difficulty inviting a friend to the match.
GKMatchRequest *request = [[[GKMatchRequest alloc] init] autorelease];
request.minPlayers = 2;
request.maxPlayers = 2;
request.playersToInvite = [NSArray arrayWithObjects: @"G:1102359306",nil ];
// GKMatchmakerViewController *mv = [[GKMatchmakerViewController alloc] initWithMatchRequest:request];
// [self presentModalViewController:mv animated:YES];
[[GKMatchmaker sharedMatchmaker] findMatchForRequest:request withCompletionHandler:^(GKMatch *match, NSError *error) {
if (error) {
NSLog([error description]);
}
else if (match != nil) {NSLog(@"good match");
//self.chatMatch = match;
//self.chatMatch.delegate = self;
//[self chatReady];
}
else {
NSLog(@"other error");
}
}];
The problem is I never receive the invitation notification on second device logged to the account - G:1102359306.When I use GKMatchmakerViewController (uncomment above 2 lines) and comment GKMatchmaker block I have automatically checked the good friend - G:1102359306 and when I invites him the notification with accept/decline is shown, that's how I know it's correct.
Do you see anything wrong with the code above? I want to use my own UI to handle the multiplayer mode. The strange problem is I also don't see in console any logs good match/other error, and the [error description] is only printed when I call the above code twice - it says that the previous req was canceled.
You cannot programmatically invite a specific set of players to a match. The findMatchForRequest:withCompletionHandler:
documentation says this:
There is no public API that does what you want.
这篇关于游戏中心以编程方式邀请朋友的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!