2010-10-04 88 views
1

在遊戲中心蘋果文檔它說,使用此代碼來檢測,如果遊戲中心可用:如何檢測Game Center支持?

+ (BOOL) isGameCenterAvailable { 
    Class gcClass = (NSClassFromString(@"GKLocalPlayer")); 

    NSString *reqSysVer = @"4.1"; 
    NSString *currSysVer = [[UIDevice currentDevice] systemVersion]; 
    BOOL osVersionSupported = ([currSysVer compare:reqSysVer options:NSNumericSearch] != NSOrderedAscending); 

    return (gcClass && osVersionSupported); 
} 

但它在我的iPhone 3G的返回是不具有遊戲中心。誰已經解決了這個問題?

回答

0

答案是,你不能。蘋果希望我們嘗試登錄以查看Game Center是否在那裏。奇怪,但事實就是這樣。

1

我沒有試過,但嘗試獲得當地玩家單:

if (![gcClass localPlayer]) { 
    // then you havnt got game center support 
} 
+0

感謝,但這並不能工作。看起來蘋果計劃在3G上支持Game Center,但最後還是拿下了它...... – PEZ 2010-10-04 20:36:13

+0

你永遠無法在3G手機上獲得認證...所以只要你正在測試這個,那麼它不應該是你在什麼硬件上的問題。 – 2010-10-04 20:49:28

+1

問題是,如果我嘗試進行身份驗證,則受支持設備上的用戶將獲得登錄對話框。該對話並沒有提到任何關於Game Center的內容(不知道蘋果爲什麼這麼做)。我試圖通過提供一個啓動應用程序的Game Center功能的按鈕來解決這個問題。如果遊戲中心不可用,我不想顯示那個按鈕。 – PEZ 2010-10-05 04:27:06

2

實際上,您可以檢查您的應用程序是否可以打開gamecenter:URL方案之一。

BOOL canOpenGC = [[UIApplication sharedApplication] canOpenURL:[NSURL urlWithString:@"gamecenter:/me/account]]; 

See this StackOverflow answer on the matter