Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/113.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
GKMatchmakerViewController在iOS 7中不开放,但在iOS 5.1中工作_Ios_Cocos2d Iphone_Game Center - Fatal编程技术网

GKMatchmakerViewController在iOS 7中不开放,但在iOS 5.1中工作

GKMatchmakerViewController在iOS 7中不开放,但在iOS 5.1中工作,ios,cocos2d-iphone,game-center,Ios,Cocos2d Iphone,Game Center,我遵循了本教程,但配对窗口没有打开。源代码的DropBox链接 如果我使用这个应用程序,那么它会在iOS 6及以上版本中崩溃,但会打开GKMatchmakerViewController - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Init the window self.window = [[UI

我遵循了本教程,但配对窗口没有打开。源代码的DropBox链接

如果我使用这个应用程序,那么它会在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]];
}
- (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!");
    }
}

几个月前我遇到了同样的问题,我解决这个问题的方法是将mmvc作为模态视图控制器。请尝试用以下内容替换您的else:

[presentingViewController dismissModalViewControllerAnimated:NO];
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 presentModalViewController:mmvc animated:YES];

self.pendingInvite = nil;
self.pendingPlayersToInvite = nil;
此外,您的身份验证似乎存在问题。您的方法应使用新的播放器身份验证机制,如:

- (void)authenticateLocalUser { 

    if (!gameCenterAvailable) return;

    NSLog(@"Authenticating local user...");
    if ([GKLocalPlayer localPlayer].authenticated == NO) {

        // Use new authentication mechanism if the iOS version is 6.0 or above
        if ([[UIDevice currentDevice].systemVersion compare:@"6.0" options:NSNumericSearch] != NSOrderedAscending) {
            [[GKLocalPlayer localPlayer] setAuthenticateHandler:^(UIViewController *vc, NSError *error) {
                if (error)
                    NSLog(@"Error in authenticating User - %@", [error localizedDescription]);
                else if (vc) {
                    AppDelegate *appDel = (AppDelegate *)[UIApplication sharedApplication].delegate;
                    [appDel.navigationController presentModalViewController:vc animated:YES];
                }
            }];
        }
        else
            [[GKLocalPlayer localPlayer] authenticateWithCompletionHandler:nil];
    }
    else {
        NSLog(@"Already authenticated!");
    }
}

调用此方法时,“gameCenterAvailable”中的值是多少?@nomanasim-我正在ios 7.0上测试它,以便gamecenter可用,并且在调试时,它正在输入其他部分。您的配对代码可能没有任何问题。我认为您在身份验证过程中失败了。你能粘贴你的“authenticateLocalUser”代码吗?@nomanasim-请查看我的更新问题我也共享了源代码正如我所怀疑的,你正在使用authenticateWithCompletionHandler进行身份验证,该身份验证在iOS 6.0之后被弃用并最终删除。因此,我认为您的播放器将无法在较新的iOS版本中获得身份验证。我已经用正确的方式更新了我的答案。@nomanasim-谢谢你的关心。但在appdelegatelet类型的对象上找不到属性navigationController时出错
- (void)authenticateLocalUser { 

    if (!gameCenterAvailable) return;

    NSLog(@"Authenticating local user...");
    if ([GKLocalPlayer localPlayer].authenticated == NO) {

        // Use new authentication mechanism if the iOS version is 6.0 or above
        if ([[UIDevice currentDevice].systemVersion compare:@"6.0" options:NSNumericSearch] != NSOrderedAscending) {
            [[GKLocalPlayer localPlayer] setAuthenticateHandler:^(UIViewController *vc, NSError *error) {
                if (error)
                    NSLog(@"Error in authenticating User - %@", [error localizedDescription]);
                else if (vc) {
                    AppDelegate *appDel = (AppDelegate *)[UIApplication sharedApplication].delegate;
                    [appDel.navigationController presentModalViewController:vc animated:YES];
                }
            }];
        }
        else
            [[GKLocalPlayer localPlayer] authenticateWithCompletionHandler:nil];
    }
    else {
        NSLog(@"Already authenticated!");
    }
}