2012-07-22 79 views
1

繼書本教程後,似乎遇到了「isGameCenterAvailable」錯誤。未聲明的標識符「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 
+0

也謝謝,未經申明的代表也有同樣的問題。除了代表我做同樣的事情還是有更多的 – 2012-07-22 04:49:14

+0

對不起,只是編輯它大聲笑 – 2012-07-22 04:51:28

+0

你從哪裏得到錯誤(哪個文件,哪一行)? – pasawaya 2012-07-22 04:53:40

回答

1

問題是你從來沒有實際申報isGameCenterAvailable。爲了解決這個問題,這樣做:

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

//HelloWorldLayer.m 
@synthesize isGameCenterAvailable = _isGameCenterAvailable; 

UPDATE:

要解決委託錯誤,試試這個:

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

//HelloWorldLayer.m 
@synthesize delegate; 

希望這有助於!

+0

謝謝,我確實有一個鏈接錯誤,但在求助之前,我試圖找出自己的錯誤。真的很感激它。 – 2012-07-22 05:09:59

+0

@JonDoe - 當然。如果你自己弄不明白,隨時可以詢問鏈接器錯誤。 – pasawaya 2012-07-22 05:10:50