Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 如何测试游戏中心是否可用?_Iphone_Objective C_Game Center - Fatal编程技术网

Iphone 如何测试游戏中心是否可用?

Iphone 如何测试游戏中心是否可用?,iphone,objective-c,game-center,Iphone,Objective C,Game Center,我刚刚在我的应用程序中实现了game center支持,如这里所述 它是作为一个单件实现的。在我的应用程序代理中: // At the end of applicationDidFinishLaunching, right before // the last line that calls runWithScene: [[GCHelper sharedInstance] authenticateLocalUser]; 对方法和属性的一点概述: @interface

我刚刚在我的应用程序中实现了game center支持,如这里所述

它是作为一个单件实现的。在我的应用程序代理中:

    // At the end of applicationDidFinishLaunching, right before 
    // the last line that calls runWithScene:
    [[GCHelper sharedInstance] authenticateLocalUser];
对方法和属性的一点概述:

@interface GCHelper : NSObject {
    BOOL gameCenterAvailable;
    BOOL userAuthenticated;
}

@property (assign, readonly) BOOL gameCenterAvailable;

+ (GCHelper *)sharedInstance;
- (void) authenticateLocalUser;

@end
由于我的应用程序代理中现在有对GCHelper的引用,我想知道如果game center可用,如何在另一个类(我提交分数)中实际测试


如何在另一个类中获取GCHelper的singleton实例?

请查看如何在另一个类中获取singleton实例:

//数据类.h

@interface DataClass : NSObject {    

int i;   

}    
@property(nonatomic,assign)int i;    
+(DataClass*)getInstance;    
@end  
//DataClass.m

@implementation DataClass    
@synthesize i;    
static DataClass *instance =nil;    
+(DataClass *)getInstance    
{    
@synchronized(self)    
{    
    if(instance==nil)    
{    

    instance= [DataClass new];    
}    
}    
return instance;    
}    
现在,在视图控制器中,您需要调用以下方法:

DataClass *obj=[DataClass getInstance];  
obj.i= // whatever you want;  
每个视图控制器都可以访问此变量。您只需创建数据类的实例