簡體   English   中英

GKMatchmakerViewController在iOS 7中未打開,但在iOS 5.1中工作

[英]GKMatchmakerViewController is not opening up in iOS 7 but working in iOS 5.1

我按照本教程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.zip

- (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!");
    }
}

好幾個月前,我遇到了同樣的問題,而解決此問題的方法是將mmvc呈現為模態視圖控制器。 請嘗試用以下內容替換其他內容:

[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!");
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM