遵循书籍教程,似乎遇到了“isGameCenterAvailable”错误的障碍。
显然它是未声明的。其他一切似乎都有效,所以我只需要弄清楚这部分。
Helloworldlayer .m 初始化方法
#import <GameKit/GameKit.h>
GameKitHelper* gkHelper = [GameKitHelper sharedGameKitHelper]; gkHelper.delegate = self;
[gkHelper authenticateLocalPlayer];        
Class gameKitLocalPlayerClass = NSClassFromString(@"GKLocalPlayer"); bool isLocalPlayerAvailable = (gameKitLocalPlayerClass != nil);
// Test if device is running iOS 4.1 or higher
NSString* reqSysVer = @"4.1";
NSString* currSysVer = [[UIDevice currentDevice] systemVersion]; bool isOSVer41 = ([currSysVer compare:reqSysVer
                                                                                                   options:NSNumericSearch] != NSOrderedAscending);
isGameCenterAvailable = (isLocalPlayerAvailable && isOSVer41); 
-(void) onLocalPlayerAuthenticationChanged {
    [delegate onLocalPlayerAuthenticationChanged]; 
}
-(void) authenticateLocalPlayer {
    GKLocalPlayer* localPlayer = [GKLocalPlayer localPlayer]; 
    if (localPlayer.authenticated == NO) {
        [localPlayer authenticateWithCompletionHandler: ^(NSError* error) {
        [self setLastError:error]; }];
    } 
}
游戏套件.h
  #import "cocos2d.h"
 #import <GameKit/GameKit.h>
 @protocol GameKitHelperProtocol
 -(void) onLocalPlayerAuthenticationChanged; -(void) onFriendListReceived:   (NSArray*)friends; -(void) onPlayerInfoReceived:(NSArray*)players; @end
 @interface GameKitHelper : NSObject {
   id<GameKitHelperProtocol> delegate; bool isGameCenterAvailable; NSError* lastError;
}
 @property (nonatomic, retain) id<GameKitHelperProtocol> delegate;
 @property (nonatomic, readonly) bool isGameCenterAvailable; @property (nonatomic,    readonly) NSError* lastError;
+(GameKitHelper*) sharedGameKitHelper;
 // Player authentication, info
 -(void) authenticateLocalPlayer;
 -(void) getLocalPlayerFriends;
 -(void) getPlayerInfo:(NSArray*)players; 
 @end  
你好世界层.h
 #import "GameKitHelper.h"
  @interface helloworldlayer : CCLayer <GameKitHelperProtocol>
{
 }
游戏工具助手。H
 #import "cocos2d.h"
  #import <GameKit/GameKit.h>
  @protocol GameKitHelperProtocol
  -(void) onLocalPlayerAuthenticationChanged; -(void) onFriendListReceived:(NSArray*)friends; -   (void) onPlayerInfoReceived:(NSArray*)players; @end
   @interface GameKitHelper : NSObject {
id<GameKitHelperProtocol> delegate; bool isGameCenterAvailable; NSError* lastError;
}
@property (nonatomic, retain) id<GameKitHelperProtocol> delegate;
  @property (nonatomic, readonly) bool isGameCenterAvailable; @property (nonatomic,     readonly) NSError* lastError;
  +(GameKitHelper*) sharedGameKitHelper;
 // Player authentication, info
 -(void) authenticateLocalPlayer;
 -(void) getLocalPlayerFriends;
 -(void) getPlayerInfo:(NSArray*)players; 
   @end