2013-04-10 2 views
1

저는 iOS를 처음 사용하고 재미있게 차례 기반 iOS 게임을 작성하려고합니다. 지금 로컬 사용자를 인증하려고하는데이 코드는 (주기 유지 경고 임에도 불구하고) 빌드되지만 GameCenter에서 항상 인증에 실패합니다.setAuthenticateHandler가 Game Center에서 인증하지 못했습니다.

// Authenticate the local user. 
- (void)authenticateLocalUser 
{ 
if (!gameCenterAvailable) return; 

GKLocalPlayer *localPlayer = [GKLocalPlayer localPlayer]; 
[localPlayer setAuthenticateHandler:(^(UIViewController* viewcontroller, NSError *error) 
{ 
    //[localPlayer authenticateWithCompletionHandler:^(NSError *error) { OLD CODE! 
    if (localPlayer.isAuthenticated) 
    { 
     // Do some stuff. 
    } 
    else 
    { 
     UIAlertView *alertView = [[UIAlertView alloc] 
            initWithTitle:@"NOT AUTHORISED" 
            message:@"YOUR'RE NOT LOGGED INTO GC." 
            delegate:self 
            cancelButtonTitle:@"OK" 
            otherButtonTitles:nil]; 
     [alertView show]; 
    } 
} 
)]; 

}

내 예전의 코드는 여전히 작동하지만 iOS6의 감가 상각되었다

NSLog(@"Authenticating local user..."); 
if ([GKLocalPlayer localPlayer].authenticated == NO) 
{ 
    [[GKLocalPlayer localPlayer] 
    authenticateWithCompletionHandler:nil]; 
} 
else 
{ 
    NSLog(@"Already authenticated!"); 
} 

어떤 제안이?

+0

가능한 복제 http://stackoverflow.com/questions/13511030/login-in-iphone-app-via-gamekit – lostInTransit

+0

슬프게도 같은 문제는 아닙니다. –

답변

2

플레이어가 인증되지 않으면 해당 처리기는 UIViewController를 전달합니다. 보기 컨트롤러가 수신되면보기 컨트롤러를 표시하는 것은 사용자의 책임입니다.

localPlayer.authenticateHandler = ^(UIViewController *viewController, NSError *error){ 
    if (viewController != nil) { 
     [self presentViewController:viewController animated:YES completion:nil]; 
    } else if (instance.player.isAuthenticated) { 
     //Your handler will be called a second time once the user authenticates GC 
     //using the view controller above ^^^^^ 
    } else if (error != nil) { 
     //If all else fails, you'll have an error. Handle it 
    } 
}; 
0

나는 폐쇄가 인증되지 전에 나는 새로운 GKLocalPlayer.localPlayer() 객체를 검색하는 경우 동안 localPlayer가,/외부 설정,이를 인증 할 것이라는 점을 발견했다.

func authenticatePlayer() { 
    local_player.authenticateHandler = {(view_controller, error) -> Void in 

    // Note that self.local_player.authenticated and 
    // GKLocalPlayer.localPlayer().authenticated give different 
    // results 

    self.local_player = GKLocalPlayer.localPlayer() 
    if (self.local_player.authenticated) { 
     // Successfully authenticated 
    } else if (view_controller != nil) { 
     // Not yet authenticated 
    } else { 
     // authentication failed 
    } 
    } 
} 

이 경우 주위 클래스에 local_player이 설정됩니다.

참고 : 실제로 이러한 결과가 다른 이유는 분명하지 않습니다.

관련 문제