1

遵循书籍教程,似乎遇到了“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  
4

1 回答 1

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;

希望这可以帮助!

于 2012-07-22T04:52:59.293 回答