Iphone 如何测试游戏中心是否可用?
我刚刚在我的应用程序中实现了game center支持,如这里所述 它是作为一个单件实现的。在我的应用程序代理中: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
// 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;
每个视图控制器都可以访问此变量。您只需创建数据类的实例