zoukankan      html  css  js  c++  java
  • IOS GameCenter验证登陆

    #import "GameKitHelper.h"
    #import "GameConstants.h"
    
    @interface GameKitHelper ()
            <GKGameCenterControllerDelegate> {
        BOOL _gameCenterFeaturesEnabled;
    }
    @end
    
    @implementation GameKitHelper
    
    #pragma mark Singleton stuff
    
    +(id) sharedGameKitHelper {
        static GameKitHelper *sharedGameKitHelper;
        static dispatch_once_t onceToken;
        dispatch_once(&onceToken, ^{
            sharedGameKitHelper =
                    [[GameKitHelper alloc] init];
        });
        return sharedGameKitHelper;
    }
    
    #pragma mark Player Authentication
    
    -(void) authenticateLocalPlayer {
    
      GKLocalPlayer* localPlayer =
        [GKLocalPlayer localPlayer];
    
        localPlayer.authenticateHandler =
        ^(UIViewController *viewController,
          NSError *error) {
    
            [self setLastError:error];
    
            if ([CCDirector sharedDirector].isPaused)
                [[CCDirector sharedDirector] resume];
    
            if (localPlayer.authenticated) {
                _gameCenterFeaturesEnabled = YES;
            } else if(viewController) {
                [[CCDirector sharedDirector] pause];
                [self presentViewController:viewController];
            } else {
                _gameCenterFeaturesEnabled = NO;
            }
        };
    }
    @end


    #pragma mark Property setters
    
    -(void) setLastError:(NSError*)error {
        _lastError = [error copy];
        if (_lastError) {
            NSLog(@"GameKitHelper ERROR: %@", [[_lastError userInfo] 
              description]);
        }
    }
    
    #pragma mark UIViewController stuff
    
    -(UIViewController*) getRootViewController {
        return [UIApplication 
          sharedApplication].keyWindow.rootViewController;
    }
    
    -(void)presentViewController:(UIViewController*)vc {
        UIViewController* rootVC = [self getRootViewController];
        [rootVC presentViewController:vc animated:YES 
          completion:nil];
    }
  • 相关阅读:
    图像处理、分析与机器视觉读书笔记-------第二章图像及其表达与性质
    win7下VS2015+opencv3.1.0配置
    简单使用普通用户启动tomcat
    漏洞扫描,linux配置规范处理
    linux防火墙开放和禁用指定端口
    CentOS自带定时任务crontab
    linux之dos2unix命令
    CentOS7时间设置问题
    shell去除换行和空格
    log4j日志输出级别高低
  • 原文地址:https://www.cnblogs.com/zxhl/p/9796680.html
Copyright © 2011-2022 走看看