未声明的标识符“isGameCenterAvailable”

时间:2012-07-22 03:55:21

标签: objective-c ios game-center

遵循书籍教程,似乎遇到了“isGameCenterAvailable”错误。

显然它是未宣布的。其他一切似乎都有效,所以我只需要弄清楚这一部分。

Helloworldlayer .m init方法

#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]; }];
    } 
}

Gamekit.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  

helloworld layer.h

 #import "GameKitHelper.h"


  @interface helloworldlayer : CCLayer <GameKitHelperProtocol>

{



 }

gamekithelper。 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  

1 个答案:

答案 0 :(得分:1)

问题是你从未真正声明isGameCenterAvailable。要解决此问题,请执行以下操作:

//HelloWorldLayer.h
@property (nonatomic) BOOL isGameCenterAvailable;

//HelloWorldLayer.m
@synthesize isGameCenterAvailable = _isGameCenterAvailable;

<强>更新

要修复委托错误,请尝试以下操作:

//HelloWorldLayer.h
@property (nonatomic, retain) id<GameKitHelperProtocol> delegate;

//HelloWorldLayer.m
@synthesize delegate;

希望这有帮助!