Apple のゲーム センターをアプリケーションに統合しようとしています。リーダー ボードにスコアを投稿してリーダー ボードを表示することはできますが、リーダー ボードのモーダル ビューを閉じようとすると問題が発生します。ゲーム キット プログラミング ガイド ([url]http://developer.apple.com/library/ios/#documentation/NetworkingInternet/Conceptual/GameKit_Guide/LeaderBoards/LeaderBoards.html[/url]) から Apple のコードの指示に従いました。 .
Game Center のコードは次のとおりです。
-(BOOL)isGameCenterAvailable{
// Check for presence of GKLocalPlayer class.
BOOL localPlayerClassAvailable = (NSClassFromString(@"GKLocalPlayer")) != nil;
// The device must be running iOS 4.1 or later.
NSString *reqSysVer = @"4.1";
NSString *currSysVer = [[UIDevice currentDevice] systemVersion];
BOOL osVersionSupported = ([currSysVer compare:reqSysVer options:NSNumericSearch] != NSOrderedAscending);
return (localPlayerClassAvailable && osVersionSupported);
}
- (void) authenticateLocalPlayer
{
if([self isGameCenterAvailable]){
GKLocalPlayer *localPlayer = [GKLocalPlayer localPlayer];
[localPlayer authenticateWithCompletionHandler:^(NSError *error) {
if (localPlayer.isAuthenticated)
{
// Perform additional tasks for the authenticated player.
}
}];
}
}
- (void) reportScore: (int64_t) score forCategory: (NSString*) category
{
GKScore *scoreReporter = [[[GKScore alloc] initWithCategory:category] autorelease];
scoreReporter.value = score;
[scoreReporter reportScoreWithCompletionHandler:^(NSError *error) {
if (error != nil)
{
// handle the reporting error
}
}];
}
- (void) showLeaderboard
{
GKLeaderboardViewController *leaderboardController = [[GKLeaderboardViewController alloc] init];
if (leaderboardController != nil)
{
leaderboardController.leaderboardDelegate = self;
[self presentModalViewController: leaderboardController animated: YES];
}
//[leaderboardController release];
}
- (void)leaderboardViewControllerDidFinish:(GKLeaderboardViewController *)viewController
{
if([self modalViewController] != nil){
[self dismissModalViewControllerAnimated:YES];
}
}
-(IBAction)show{
[self showLeaderboard];
}
-(IBAction)submit{
[self reportScore:9 forCategory:kLeaderboardID];
}
Xcode は、問題の行が [self disconnectModalViewControllerAnimated:YES]; であることを教えてくれます。アクセスが悪いと表示されます。これは、悪いポインターにアクセスしようとしていることを意味しますが、何も無効にならない理由がわかりません。modalviewcontroller があることを自己報告します。あらゆる種類のバリアントを試しましたが、エラーが発生する理由について完全に困惑しています。
どんな助けや提案も大歓迎です。
前もって感謝します!