objective-c - 未声明的标识符 "isGameCenterAvailable"

标签 objective-c ios game-center

按照书籍教程,似乎遇到了“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  

helloworld层.h

 #import "GameKitHelper.h"


  @interface helloworldlayer : CCLayer <GameKitHelperProtocol>

{



 }

游戏 helper 。

 #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  

最佳答案

问题是您实际上从未声明过 isGameCenterAvailable。要解决此问题,请执行以下操作:

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

//HelloWorldLayer.m
@synthesize isGameCenterAvailable = _isGameCenterAvailable;

更新:

要修复委托(delegate)错误,试试这个:

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

//HelloWorldLayer.m
@synthesize delegate;

希望这对您有所帮助!

关于objective-c - 未声明的标识符 "isGameCenterAvailable",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11597656/

相关文章:

iphone - 如何将 UIButton 标题设置为 null 或空字符串

iOS 应用程序图像大小和命名约定

ios - 在 Gamecenter 中导出成就

ios - SwiftUI - 动态过滤时防止部分在列表中向右飞行/缩放

iphone - 如何使循环异常?

ios - 在游戏中心身份验证期间底层 View 消失

web-services - Apple 的游戏中心有 web api 吗?

objective-c - 确定我何时返回 ViewController

iphone - 对从 pList 加载的 UITableView 部分进行排序

ios - 视频流演示中的错误