zoukankan      html  css  js  c++  java
  • GameCenter登录代码

    参考:http://stackoverflow.com/questions/12870041/ios-6-game-center-authenticatehandler-cant-login-after-a-cancel

    static BOOL g_isGameCenterInit = NO;
    #define SYSTEM_VERSION_LESS_THAN(v) ([[[UIDevice currentDevice] systemVersion] 
    compare:v options:NSNumericSearch] == NSOrderedAscending)
    - (void)authenticateLocalUser:(id) sender
    {
        if (g_isGameCenterInit) {
            [[NSNotificationCenter defaultCenter] postNotificationName:UIApplicationWillEnterForegroundNotification object:[UIApplication sharedApplication]];
            return;
        }
        g_isGameCenterInit = YES;
        
        GKLocalPlayer *localPlayer = [GKLocalPlayer localPlayer];
        // 已登录
        if (localPlayer.isAuthenticated) {
            [self sendOk];
        } else {
            
            if (SYSTEM_VERSION_LESS_THAN(@"6.0"))
            {
                // ios 5.x and below
                [localPlayer authenticateWithCompletionHandler:^(NSError *error)
                 {
                     
                     if (localPlayer.isAuthenticated)
                     {
                         [self sendOk];
                     }
                 }];
            }
            else
            {
                // ios 6.0 and above
                [localPlayer setAuthenticateHandler:(^(UIViewController* viewController, NSError *error) {
                    [[CCDirector sharedDirector] resume];
                    
                    if (error && error.code == GKErrorCancelled) {
                        NSLog(@"Game Center code:%d %@", error.code, [error debugDescription]);
                        [self sendFaild];
                        return ;
                    }
                    if (localPlayer.isAuthenticated) {
                        [self sendOk];
                    }
                    else if (viewController) {
                        [[CCDirector sharedDirector] pause];
                        AppDelegate* delegate = (AppDelegate*)[UIApplication sharedApplication].delegate;
                        RootViewController* root = (RootViewController*)delegate.viewController;
                        [root presentViewController:viewController animated:YES completion:nil];
                    }
                })];
            }
        }
    }


  • 相关阅读:
    初始FreeMake
    C#三层架构
    文件上传
    Jquery动画效果(混合)
    反射机制
    Java使用Sockt进行通信(2)
    Java使用Socket进行通信
    JavaScript基础
    Java的继承
    事物>视图>索引>备份和恢复
  • 原文地址:https://www.cnblogs.com/iapp/p/3631689.html
Copyright © 2011-2022 走看看