游戏中心以编程方式邀请好友

发布于 2024-10-01 00:35:30 字数 1158 浏览 1 评论 0原文

我在邀请朋友观看比赛时遇到困难。

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 来处理多人游戏模式。奇怪的问题是我在控制台中也没有看到任何日志良好匹配/其他错误,并且仅当我两次调用上述代码时才会打印[错误描述] - 它表示先前的请求已被取消。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

花之痕靓丽 2024-10-08 00:35:30

您无法以编程方式邀请一组特定的玩家参加比赛。 findMatchForRequest:withCompletionHandler: 文档 说:

匹配请求的 playersToInvite 属性被忽略;要邀请一组特定的玩家参加比赛,您必须显示匹配器视图控制器。

没有公共 API 可以满足您的要求。

You cannot programmatically invite a specific set of players to a match. The findMatchForRequest:withCompletionHandler: documentation says this:

The match request’s playersToInvite property is ignored; to invite a specific set of players to the match, you must display a matchmaker view controller.

There is no public API that does what you want.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文