- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
在 iOS 7 中处理来自其他玩家的邀请的正确方法是什么?
在我的 View 确实加载到我的 Root View Controller 上之后,我调用了游戏中心身份验证方法,之后我设置了一个邀请处理程序,如下所示:
[[GKLocalPlayer localPlayer] registerListener:self];
我的 View Controller 采用GKLocalPlayerListener
和GKInviteEventListener
协议(protocol),顺便问一下,注册监听器AppDelegate 的最佳位置是什么?也许或者也许是我的自定义 Game Center 单例?
我添加了 GKInviteEventListener
中描述的方法
-(void)player:(GKPlayer *)player didAcceptInvite:(GKInvite *)invite
{
NSLog(@"Invite accepted!");
GKMatchmakerViewController *mmvc = [[GKMatchmakerViewController alloc] initWithInvite:invite];
mmvc.matchmakerDelegate = self;
[self presentViewController:mmvc animated:YES completion:nil];
}
但是,游戏中心的媒人类有这样的话题:Receiving Invitations From Other Players and method – matchForInvite:completionHandler:
我不明白如何使用它。
那么,我必须使用什么以及如何使用?
最佳答案
我认为你做的事情是正确的。我以同样的方式做事,它对我有用。 -matchForInvite:completionHandler
在 iOS 7 中已被弃用,所以我没有对它做任何事情。
首先我设置了身份验证处理程序。这是在我的应用程序首次加载时调用的,您可以将其设置在任何您喜欢的位置,但最好尽快设置处理程序。
-(void)authenticateLocalPlayer
{
GKLocalPlayer *localPlayer = [GKLocalPlayer localPlayer];
__weak GKLocalPlayer *blockLocalPlayer = localPlayer;
//Block is called each time GameKit automatically authenticates
localPlayer.authenticateHandler = ^(UIViewController *viewController, NSError *error)
{
[self setLastError:error];
if (viewController)
{
self.authenticationViewController = viewController;
[self disableGameCenter];
}
else if (blockLocalPlayer.isAuthenticated)
{
[self authenticatedPlayer:blockLocalPlayer];
}
else
{
[self disableGameCenter];
}
};
}
如果身份验证成功,则调用此方法:
-(void)authenticatedPlayer:(GKLocalPlayer*)localPlayer
{
self.isAuthenticated = YES;
[[NSNotificationCenter defaultCenter]postNotificationName:AUTHENTICATED_NOTIFICATION object:nil];
[[GKLocalPlayer localPlayer]registerListener:self];
}
然后我实现了两个监听方法:
(void)player:(GKPlayer *)player didAcceptInvite:(GKInvite *)invite
{
//.... insert some cleanup code here to manage view controllers etc before presenting the matchmakerviewcontroller.
[self presentMatchmakerViewControllerWithInvite:invite];
}
-(void)player:(GKPlayer *)player didRequestMatchWithPlayers:(NSArray *)playerIDsToInvite
{
//......insert some cleanup code for managing view controllers
GKMatchRequest *match = [[GKMatchRequest alloc]init];
match.playersToInvite = playerIDsToInvite;
GKMatchmakerViewController *mmvc = [[GKMatchmakerViewController alloc]initWithMatchRequest:match];
mmvc.matchmakerDelegate = root.viewControllers[0];
[[[[[UIApplication sharedApplication]delegate]window]rootViewController]presentViewController:mmvc animated:YES completion:nil];
}
关于iOS 7 : How to setup invitation handler for Game Center matchmaker,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21166617/
在我的应用中,我使用 IntentService 发送短信。 @Override protected void onHandleIntent(Intent intent) { Bund
Handler(android.os.Handler.Callback) 已弃用,我应该改用什么? Handler handler = new Handler(new Handler.Callback
机器人Handler类包含此方法: public final boolean postAtTime (Runnable r, Object token, long uptimeMillis) 在给定时
我不明白怎么用这个方法, sensorManager.registerListener(SensorEventListener listener, Sensor sensor, int rate, H
请告诉我 handler.postAtTime 和 handler.postDelayed 在 android 中的区别,也请指导我何时使用 handler.postAtTime 以及何时使用 han
我有以下代码。 function myFun() { alert(5) } $(document).ready(fu
我有this jsfiddle 它使用 toggle event - 不要与 toggle 混淆- jQuery 版本设置为 EDGE 它突然停止工作并删除了我想要作为触发器的单元格,因为它显然恢复为
在我的应用程序中,我定义了一个自定义事件,我希望为其设置默认处理程序。如果任何 Controller /服务想要覆盖默认处理,他们可以通过添加自己的处理程序来实现。 为了实现这个场景,我在 $root
我在我的网页中使用了 jquery .toggle(between two functions) : $( ".cpUpbtnsclass" ).toggle(function() { c
我有this jsfiddle 它使用 toggle event - 不要与 toggle 混淆- jQuery 版本设置为 EDGE 它突然停止工作并删除了我想要作为触发器的单元格,因为它显然恢复为
我浏览了官方文档,但我似乎找不到 new Handler() 之间是否有任何区别和new Handler(Looper.myLooper()) new Handler() Default constr
当我在 faces-config.xml 文件中添加以下行时: " com.sun.facelets.FaceletViewHandler " eclipse 说: " view-handler re
当我使用 Handler.dispatchMessage(msg) 时,handleMessage(Message msg) 将在新线程上运行,但是当我使用 Handler.sendMessage(
如何禁用当前将模态库导航到下一张图像的鼠标滚轮处理程序和键盘箭头键? 这里是演示站点:http://blueimp.github.com/Bootstrap-Image-Gallery/ . 如果您单
我正在尝试关注 this关于 Win32 结构化异常处理的文章。这篇文章很老了,但仍然被认为是对该主题的一个很好的介绍。 我正在尝试从下面转载的文章中编译代码示例 - //==============
我正在尝试使用 HibernateValidator 使用 Spring 和 Hibernate 在 JSP 中验证一个简单的表单. JSP页面Temp.jsp如下(web.xml中的url ptte
问题几乎概括了它。我错误地导入了 java.util.logging 并且没有获得所需的功能。现在我解决了我的问题,但我想知道为什么 android 创建了两个 Handler 。我们可能会错误地导入
我有一个主页,其中有一个链接按钮。在其中一个内容页面中,我需要隐藏链接按钮并替换为图像按钮。图像按钮的单击事件处理程序应该与母版页中链接按钮的单击事件完全相同。那么有没有办法从内容页面中的图像按钮单击
我有一个用 2.5 编写的现有 Spring MVC 应用程序。 我想使用新的注释 Controller 。我在某种程度上发现它非常灵活并且可以满足我的其他需求。 我的问题是,我似乎无法将它们两者混合
使用最新的 XCode,我收到此错误: 'logInWithReadPermissions(_:handler:)' is deprecated: use logInWithReadPermissi
我是一名优秀的程序员,十分优秀!