iOS开发:收到Game Center邀请时,如何获取GKMatch对象?

发布于 2024-10-10 22:37:05 字数 668 浏览 2 评论 0原文

我正在构建一款使用 Game Center 的 iPhone 游戏,但我很难理解如何开始一场通过收到朋友的玩邀请而开始的比赛游戏。 文档这样说...

acceptedInvite参数是 当应用程序收到时非零 直接来自他人的邀请 玩家。在这种情况下,另一个 玩家的申请已经 创建了匹配请求,所以这 不需要您的申请副本 创建一个。

据此,我不需要创建比赛请求,因为发出邀请的玩家已经创建了比赛请求。如果是这样,我如何获取向其他玩家发送数据/从其他玩家接收数据所需的 GKMatch 对象?我知道获取 GKMatch 对象的唯一方法是创建匹配请求并调用 findMatchForRequest 方法,文档说我不应该这样做。

他们为此提供的唯一代码示例涉及创建和使用 GKMatchmakerViewController ,但我无法使用它,因为我正在创建自己的自定义视图。

非常感谢您的智慧!

I'm building an iPhone game that uses Game Center and I'm having a hard time understanding how to start a match game that was started by receiving an invitation to play from a friend. The docs say this...

The acceptedInvite parameter is
non-nil when the application receives
an invitation directly from another
player. In this situation, the other
player’s application has already
created the match request, so this
copy of your application does not need
to create one.

According to this, I don't need to create a match request since the player who did the inviting already created one. If so, how do I obtain the GKMatch object needed to send/receive data to/from the other player? The only way that I know to get the GKMatch object is to create a match request and call the findMatchForRequest method, which the docs are saying I shouldn't do.

The only code example they have for this involves creating and using the GKMatchmakerViewController, which I can't use since I'm creating my own custom views.

Thanks so much for your wisdom!

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

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

发布评论

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

评论(3

一场春暖 2024-10-17 22:37:05

我收到了一位苹果工程师的回复,他是这么说的……

您可以与自定义进行自动匹配
视图,但是没有办法使用
邀请而不使用
GKMatchmakerViewController。所以你
应遵循代码示例。

我想我的用户界面的一致性必须彻底改变。

I received a response from one of the Apple engineers on this, here's what he said...

You can do auto-matching with custom
views, but there is no way to use
invites without using
GKMatchmakerViewController. So you
should follow the code sample.

I guess there's just going to have to be a radical break in the consistency of my UI.

梦里泪两行 2024-10-17 22:37:05

我已修复游戏中心邀请问题。因此,请按照以下步骤操作:-
1- 检查您的推送通知是否已在设置中开启,并且朋友邀请是否已在您的游戏中心帐户设置中开启。
2-现在安装最新版本的水果忍者游戏
3-打开游戏中心并登录,然后将其置于后台。
4-打开水果忍者直接进入新游戏=>多人=>游戏中心
5-现在您将看到两个选项(邀请朋友并立即在右上角玩)
6-点击立即游戏按钮,游戏中心将为您找到不受欢迎的游戏。
7-当游戏开始时,你可以在右上角看到你不邀请的朋友的名字。游戏结束后,直接进入后台游戏中心的游戏部分,进入游戏列表中的水果忍者。在这里您将看到最近播放的选项,触摸它。在这里,您将在列表顶部看到一个玩家名称(与您一起玩过的玩家),触摸该名称即可立即向他发送好友请求。
8-如果他接受请求,转到朋友=>(您最近添加的朋友)=>一起玩游戏(水果忍者)=>点击游戏(右上角)
9-现在游戏将打开,您将看到GC页面。点击邀请按钮并选择最近添加的朋友,然后发送,等待他并准备好玩。

现在您的gc id已验证,您可以邀请您的任何朋友并可以玩任何游戏(支持邀请功能)

I have a fix to the game center invite problem. So follow these steps:-
1- check that your push notifications are on in settings and friend invites are on in your game center account setting.
2-now install the latest version of fruit ninja game
3-open game center and sign in, then put it in background.
4-open fruit ninja directly goto new game=>multiplayer=>gamecenter
5-now you will see two options (invite friend & play now at the top right corner)
6-hit the play now button, so the game center will find the uninvited game for you.
7-when the game starts and you are able to see your uninvited friend's name at the top right corner. After the game finishes, go directly to game center in the background and in your games section and go into fruit ninja in game list. Here you will see the recently played option, Touch it. Here you will see at the top of the list a player name (who you played with) touch the name and send him friend request immediately.
8-if he accepts request goto friends=>(your recently added friend)=>gameplayed together(fruit ninja)=>hit play(at upper right)
9-now the game will open up and you will see the GC page. Hit the invite button and choose the recently added friend, and then send, waiting for him and ready to play.

Now your gc id have verified and you can invite any of your friends and can play any game(which supports the invite feature)

在风中等你 2024-10-17 22:37:05

不管苹果工程师怎么说,尝试这样的方法来邀请而不使用自定义视图怎么样:

[[GKLocalPlayer localPlayer] loadFriendsWithCompletionHandler:^(NSArray *friends, NSError *error) {



[GKPlayer loadPlayersForIdentifiers:friends withCompletionHandler:^(NSArray *players, NSError *error) {
    for (GKPlayer *player in players) {
        NSLog(@"%@",player.alias); //here I'm just logging the aliases but the array players can be used in any way
    }
}];

} ];

现在,如果用户在自定义视图上从此列表中选择玩家,GKMatchRequest 有一个名为playersToInvite 的属性,我们可以将这些玩家设置为该属性。并使用此请求以编程方式创建匹配。

这看起来很有可能,但说实话我还没有尝试过

Despite what the Apple engineer said, how about try something like this to invite without using a custom view:

[[GKLocalPlayer localPlayer] loadFriendsWithCompletionHandler:^(NSArray *friends, NSError *error) {



[GKPlayer loadPlayersForIdentifiers:friends withCompletionHandler:^(NSArray *players, NSError *error) {
    for (GKPlayer *player in players) {
        NSLog(@"%@",player.alias); //here I'm just logging the aliases but the array players can be used in any way
    }
}];

} ];

Now if a user selects players from this list on a custom view, GKMatchRequest has a property called playersToInvite and we can set these players to that property. And create a match programmatically using this request.

This looks very possible but I haven't tried it to be honest

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