2010-12-13 45 views
1

我試圖檢測本地播放器身份驗證是否正常工作,看起來我總是得到一個積極的結果。遊戲中心localPlayer始終認證

這裏是我使用的代碼:我測試這個代碼,同時斷開網絡連接,並在這裏

//-------------------------------------------------------------- 
- (void)authenticateLocalPlayer 
{ 
    NSLog(@"Authenticating local player %@ (%d)", ([GKLocalPlayer localPlayer].authenticated? @"YES":@"NO"), [GKLocalPlayer localPlayer].authenticated); 
    if ([GKLocalPlayer localPlayer].authenticated == NO) { 
     [[GKLocalPlayer localPlayer] authenticateWithCompletionHandler:^(NSError *error) { 
      [self callDelegateOnMainThread:@selector(authenticationChanged:) 
            withArg:nil 
            error:error]; 
     }]; 
    } 
} 

//-------------------------------------------------------------- 
- (void)authenticationChanged:(NSError *)error { 
    if (error != nil) { 
     NSLog(@"Error authenticating local player: %@", [error localizedDescription]); 
    } 
    NSLog(@"Authentication changed %@ (%d)", ([GKLocalPlayer localPlayer].authenticated? @"YES":@"NO"), [GKLocalPlayer localPlayer].authenticated); 
} 

被跟蹤輸出:

2010-12-13 13:20:59.799 LittleScreams[954:307] Authenticating local player NO (0) 
2010-12-13 13:21:01.616 LittleScreams[954:307] Error authenticating local player: The Internet connection appears to be offline. 
2010-12-13 13:21:01.621 LittleScreams[954:307] Authentication changed YES (1) 

它清楚地看到,連接離線但仍在認證玩家!任何想法發生了什麼?我在設備和模擬器上獲得了相同的結果。

TIA

+0

我有類似的問題。我正在測試我的遊戲中心功能,並希望看到在飛行模式下會發生什麼。如果我在進入飛行模式之前登錄了Game Center,該應用程序將不會授權玩家(當然),但是在執行[localPlayer isAuthenticated]時,我會得到一個帶登錄到Game Center的玩家ID的YES。你有沒有找到解決你的問題? – Structurer 2011-08-30 10:32:34

回答

0

我想你不應該手動調用authenticationChanged,看看遊戲套件編程指南和遵循的步驟,爲我工作。

http://developer.apple.com/library/ios/#documentation/NetworkingInternet/Conceptual/GameKit_Guide/Users/Users.html

+0

我實際上沒有手動調用它,authenticationChanged被完成處理程序調用。此代碼基於Apple的GKTapper示例:http://developer.apple.com/library/ios/#samplecode/GKTapper/Introduction/Intro.html – prisonerjohn 2010-12-20 04:05:54