我按照本教程http://www.raywenderlich.com/3276/how-to-make-a-simple-multiplayer-game-with-game-center-tutorial-part-12,但匹配窗口未打開。的源代碼的DropBox鏈路https://www.dropbox.com/s/e4pp95iqqo6xkrw/testCocos2d%202.zipGKMatchmakerViewController未在iOS 7中打開,但在iOS 5.1中工作
- (void)findMatchWithMinPlayers:(int)minPlayers maxPlayers:(int)maxPlayers viewController:(UIViewController *)viewController delegate:(id<GCHelperDelegate>)theDelegate {
if (!gameCenterAvailable) return;
matchStarted = NO;
self.match = nil;
self.presentingViewController = viewController;
delegate = theDelegate;
if (pendingInvite != nil) {
[presentingViewController dismissModalViewControllerAnimated:NO];
GKMatchmakerViewController *mmvc = [[[GKMatchmakerViewController alloc] initWithInvite:pendingInvite] autorelease];
mmvc.matchmakerDelegate = self;
[presentingViewController presentModalViewController:mmvc animated:YES];
self.pendingInvite = nil;
self.pendingPlayersToInvite = nil;
} else {
GKMatchRequest *request = [[[GKMatchRequest alloc] init] autorelease];
request.minPlayers = minPlayers;
request.maxPlayers = maxPlayers;
request.playersToInvite = pendingPlayersToInvite;
GKMatchmakerViewController *mmvc = [[[GKMatchmakerViewController alloc] initWithMatchRequest:request] autorelease];
mmvc.matchmakerDelegate = self;
[presentingViewController presentViewController:mmvc animated:YES completion:nil];
self.pendingInvite = nil;
self.pendingPlayersToInvite = nil;
}
}
如果我使用本然後應用程序在IOS 6和上述BT犯規打開GKMatchmakerViewController
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Init the window
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
CCDirector *director = [CCDirector sharedDirector];
EAGLView *glView = [EAGLView viewWithFrame:[self.window bounds]
pixelFormat:kEAGLColorFormatRGB565 // kEAGLColorFormatRGBA8
depthFormat:0 // GL_DEPTH_COMPONENT16_OES
];
// attach the openglView to the director
[director setOpenGLView:glView];
// // Enables High Res mode (Retina Display) on iPhone 4 and maintains low res on all other devices
if(! [director enableRetinaDisplay:YES])
CCLOG(@"Retina Display Not supported");
[director setAnimationInterval:1.0/60];
// make the OpenGLView a child of the view controller
[viewController setView:glView];
// make the View Controller a child of the main window
self.window.rootViewController = viewController;
if(! [director enableRetinaDisplay:YES])
CCLOG(@"Retina Display Not supported");
// Create a Navigation Controller with the Director
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:director];
navController.navigationBarHidden = YES;
NSString *reqSysVer = @"6.0";
NSString *currSysVer = [[UIDevice currentDevice] systemVersion];
if ([currSysVer compare:reqSysVer options:NSNumericSearch] != NSOrderedAscending)
{
[self.window setRootViewController:navController];
} else
{
[self.window addSubview: navController.view];
}
[self.window makeKeyAndVisible];
[CCTexture2D setDefaultAlphaPixelFormat:kCCTexture2DPixelFormat_RGBA8888];
// Removes the startup flicker
[self removeStartupFlicker];
[[GCHelper sharedInstance] authenticateLocalUser];
// Run the intro Scene
[[CCDirector sharedDirector] runWithScene: [HelloWorldLayer scene]];
}
如果我使用本然後應用在IOS 6崩潰向上運行並以上,但開放GKMatchmakerViewController
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Init the window
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
CCDirector *director = [CCDirector sharedDirector];
EAGLView *glView = [EAGLView viewWithFrame:[self.window bounds]
pixelFormat:kEAGLColorFormatRGB565 // kEAGLColorFormatRGBA8
depthFormat:0 // GL_DEPTH_COMPONENT16_OES
];
// attach the openglView to the director
[director setOpenGLView:glView];
// // Enables High Res mode (Retina Display) on iPhone 4 and maintains low res on all other devices
if(! [director enableRetinaDisplay:YES])
CCLOG(@"Retina Display Not supported");
[director setAnimationInterval:1.0/60];
// make the OpenGLView a child of the view controller
[viewController setView:glView];
// make the View Controller a child of the main window
self.window.rootViewController = viewController;
if(! [director enableRetinaDisplay:YES])
CCLOG(@"Retina Display Not supported");
// Create a Navigation Controller with the Director
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:director];
navController.navigationBarHidden = YES;
NSString *reqSysVer = @"6.0";
NSString *currSysVer = [[UIDevice currentDevice] systemVersion];
if ([currSysVer compare:reqSysVer options:NSNumericSearch] != NSOrderedAscending)
{
[self.window setRootViewController:navController];
} else
{
[self.window addSubview: navController.view];
}
[self.window makeKeyAndVisible];
[CCTexture2D setDefaultAlphaPixelFormat:kCCTexture2DPixelFormat_RGBA8888];
// Removes the startup flicker
[self removeStartupFlicker];
[[GCHelper sharedInstance] authenticateLocalUser];
// Run the intro Scene
[[CCDirector sharedDirector] runWithScene: [HelloWorldLayer scene]];
}
用戶認證的代碼
- (void)authenticateLocalUser {
if (!gameCenterAvailable) return;
NSLog(@"Authenticating local user...");
if ([GKLocalPlayer localPlayer].authenticated == NO) {
[[GKLocalPlayer localPlayer] authenticateWithCompletionHandler:nil];
} else {
NSLog(@"Already authenticated!");
}
}
當調用此方法時,'gameCenterAvailable'中的值是什麼? – nomann
@ nomannasim-我在ios 7.0上測試它,所以gamecenter是可用的,當我調試它時,輸入在其他部分 – iOS