问题描述
我一直在开发一款可以进行多人比赛的游戏。我之前测试过多人游戏邀请函,但他们都已经完成了。从一个设备发送请求在另一个设备上显示横幅,如果邀请被接受则游戏开始。
I have been developing a game which allows for multiplayer matches. I had previous tested the multiplayer invitations and they had all worked. Sending a request from one device displayed a banner on the other and if the invite was accepted the game started.
在提交应用程序之前,两天前,我测试了这个功能再次发现它已经停止工作。
Just before submitting the app, two nights ago, I tested this functionality again only to find that it has stopped working.
- (void)authenticateLocalUser:(UIViewController *)viewController :(id<GCHelperDelegate>)theDelegate
{
delegate = theDelegate;
self.presentingViewController = viewController;
if (!gameCenterAvailable) {
// Game Center is not available.
userAuthenticated = FALSE;
}
else{
GKLocalPlayer *localPlayer = [GKLocalPlayer localPlayer];
/*
The authenticateWithCompletionHandler method is like all completion handler methods and runs a block
of code after completing its task. The difference with this method is that it does not release the
completion handler after calling it. Whenever your application returns to the foreground after
running in the background, Game Kit re-authenticates the user and calls the retained completion
handler. This means the authenticateWithCompletionHandler: method only needs to be called once each
time your application is launched. This is the reason the sample authenticates in the application
delegate's application:didFinishLaunchingWithOptions: method instead of in the view controller's
viewDidLoad method.
Remember this call returns immediately, before the user is authenticated. This is because it uses
Grand Central Dispatch to call the block asynchronously once authentication completes.
*/
//ios 6
[localPlayer setAuthenticateHandler:(^(UIViewController* viewcontroller, NSError *error) {
if (viewcontroller != nil){
userAuthenticated = FALSE;
[self.presentingViewController presentViewController: viewcontroller animated: YES completion:nil];
}
else if (localPlayer.isAuthenticated){
// Enable Game Center Functionality
userAuthenticated = TRUE;
[self checkForInvite:self.presentingViewController :delegate];
if (! self.currentPlayerID || ! [self.currentPlayerID isEqualToString:localPlayer.playerID]) {
// Current playerID has changed. Create/Load a game state around the new user.
self.currentPlayerID = localPlayer.playerID;
// get friends of local player
[localPlayer loadFriendsWithCompletionHandler:^(NSArray *friends, NSError *error) {
if (friends != nil)
{
[self loadPlayerData: friends];
}
}];
}
}
else{
userAuthenticated = FALSE;
}
[scoreHandler setGameCentreAvailable:userAuthenticated];
})];
}
}
- (void)checkForInvite :(UIViewController *)viewController :(id<GCHelperDelegate>)theDelegate
{
delegate = theDelegate;
self.presentingViewController = viewController;
NSLog(@"Invite handler installed");
[GKMatchmaker sharedMatchmaker].inviteHandler = ^(GKInvite *acceptedInvite, NSArray *playersToInvite) {
// Insert application-specific code here to clean up any games in progress.
if (acceptedInvite){
NSLog(@"Accepted");
GKMatchmakerViewController *mmvc = [[[GKMatchmakerViewController alloc] initWithInvite:acceptedInvite] autorelease];
mmvc.matchmakerDelegate = self;
[viewController presentViewController: mmvc animated: YES completion:nil];
} else if (playersToInvite) {
NSLog(@"Match Request");
GKMatchRequest *request = [[[GKMatchRequest alloc] init] autorelease];
request.minPlayers = 2;
request.maxPlayers = 2;
request.playersToInvite = playersToInvite;
GKMatchmakerViewController *mmvc = [[[GKMatchmakerViewController alloc] initWithMatchRequest:request] autorelease];
mmvc.matchmakerDelegate = self;
[viewController presentViewController: mmvc animated: YES completion:nil];
}
};
}
xcode中的调试窗口显示以下内容:
The debug window in xcode shows the following:
2013-03-27 18:06:20.112 MyApp[791:907] Authentication changed: player authenticated.
2013-03-27 18:06:21.219 MyApp[791:907] Invite handler installed
Mar 27 18:06:21 Neils-iPhone MyApp[791] <Notice>: 18:06:21.356712 com.apple.GameKitServices: -[GKDiscoveryManager startAdvertisingLocalPlayer:discoveryInfo:]: I am [<nil>] [7989F444CF2BDA83] discoveryInfo [{
e = 2;
h = A42FD7FD;
}]
我是[] ......在行中是否显着以上?
Is the "I am []..." significant in the lines above?
我甚至已经从Ray Wenderlich的网站下载并运行教程来创建一个多人游戏并尝试过。除非它在两个设备上的前台运行,否则它会出现同样的问题。即使在前台运行,我的应用也不会显示邀请请求。
I have even downloaded and run the tutorial from Ray Wenderlich's site for creating a multiplayer game and tried that. That exhibits the same issues, unless it is running in the foreground on both devices. My app does not display invitation requests even if running in the foreground.
是否有其他人遇到此问题或有任何想法发生了什么?从applicationDidFinishLaunching中调用authenticateLocalUser
Has anyone else experienced this problem or have any ideas what is going on? authenticateLocalUser is called from applicationDidFinishLaunching
推荐答案
我可以按名称工作的唯一方法是转到设置/通知/游戏中心
并使游戏中心显示 提醒 ,而不是横幅。
The only way I could make invites-by-name work is by going to Settings/Notifications/Game Center
and making Game Center display Alerts, not Banners.
如果你有GC显示警报,你会得到一个这样的弹出框:
If you have GC display alerts, you get a popup box like this:
此对话框就像一个大父母。如果用户点击接受
,则会调用 [GKMatchmaker sharedMatchmaker] .inviteHandler
。
This dialog acts like a big parent. If the user hits Accept
, then your [GKMatchmaker sharedMatchmaker].inviteHandler
gets invoked.
如果用户点击拒绝
,则您的游戏永远不会知道他曾被邀请参加任何一方。用户点击拒绝
表示父母撕毁了邀请,从未告诉他的孩子他被邀请参加游戏。
If the user hits Decline
, then your game never knows that he was invited to any party ever. User hitting Decline
means the parent rips up the invitation and never tells his child he got invited to a game at all.
这是我可以获得名人工作的唯一方式。
This is the only way I could get invite-by-name to work.
这篇关于未显示游戏中心邀请的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!