Game Center を使用するゲームがあるので、オンラインのチュートリアルを使用しました。ビューがロードされたときにユーザーを認証します。リーダーボードと実績を表示するには、ボタンを押します。そのコードは認証とは別のものです。機内モードでアプリを起動するまでは、すべて正常に機能していました。なぜかゲームセンターサーバーに接続できず、断念してクラッシュ。
認証コード (ViewController.m、viewDidLoad)
if ([GKLocalPlayer localPlayer].authenticated == NO) {
GKLocalPlayer *localPlayer = [GKLocalPlayer localPlayer];
[localPlayer setAuthenticateHandler:(^(UIViewController* viewcontroller, NSError *error) {
})];
} else {
NSLog(@"Already authenticated!");
}
また、起動時にクラッシュし、このコードが起動時に実行されるかどうかわからないため、これが問題を引き起こしているとは思いません。(このコードのほとんどをチュートリアルからコピーしました)が、ここにあります:
(GCHelper.m)
#pragma mark Authentication
- (void)authenticationChanged {
if ([GKLocalPlayer localPlayer].isAuthenticated && !userAuthenticated) {
NSLog(@"Authentication changed: player authenticated.");
userAuthenticated = TRUE;
[self loadLeaderBoardInfo];
// [self loadAchievements];
} else if (![GKLocalPlayer localPlayer].isAuthenticated && userAuthenticated) {
NSLog(@"Authentication changed: player not authenticated.");
userAuthenticated = FALSE;
}
}
- (void)authenticateLocalUserOnViewController:(UIViewController*)viewController
setCallbackObject:(id)obj
withPauseSelector:(SEL)selector
{
if (!gameCenterAvailable) return;
GKLocalPlayer *localPlayer = [GKLocalPlayer localPlayer];
NSLog(@"Authenticating local user...");
if (localPlayer.authenticated == NO) {
[localPlayer setAuthenticateHandler:^(UIViewController* authViewController, NSError *error) {
if (authViewController != nil) {
if (obj) {
[obj performSelector:selector withObject:nil afterDelay:0];
}
[viewController presentViewController:authViewController animated:YES completion:^ {
}];
} else if (error != nil) {
// process error
}
}];
}
else {
NSLog(@"Already authenticated!");
}
}
私の質問は、機内モードでの起動時にクラッシュするのはなぜですか? これはエラーメッセージです:
2014-10-28 16:18:05.895 Rock Paper Scissors Challenge[10372:704073] -[GKLocalPlayerInternal name]: インスタンス 0x7ced9750 に送信された認識されないセレクター
2014-10-28 16:18:05.992 Rock Paper Scissors Challenge[10372:704073] *キャッチされていない例外 'NSInvalidArgumentException' が原因でアプリを終了しています。スタック:
機内モードでは 100% の確率でクラッシュしますが、100% の確率で機能し、機内モードではないときに「おかえりなさい」と表示されます。
助けてください、ありがとう!