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];
    }
  • 相关阅读:
    SpringMVC-Day1 (课题有用)
    Spring-Day3
    Spring-Day2
    fix mac
    新西兰产假(陪产假)
    nz 国内航空
    英文句子
    centos7.2安装swoole扩展
    linux搭建vue框架部署环境
    微信扫描带参数二维码事件
  • 原文地址:https://www.cnblogs.com/zxhl/p/9796680.html
Copyright © 2011-2022 走看看