[Tutorial] - [iOS] - Setting Up Google Play Services for Cocos2d-x

  • GAZ99 admin
    Likes 1

    Problem Description

    Video Link:

    Google Developer Console : https://play.google.com/apps/publish/

    Helper Files Link : https://github.com/cpinan/Cocos2dX_GooglePlayGamesServices – credit to Carlos Eduardo Piñan Indacochea

     

    AppController.h

    #import <UIKit/UIKit.h>
    
    #import <GooglePlus/GooglePlus.h>
    #import <GooglePlayGames/GooglePlayGames.h>
    
    @class RootViewController;
    
    @interface AppController : NSObject <UIApplicationDelegate, GPPSignInDelegate> {
        UIWindow *window;
        RootViewController *viewController;
    }
    
    @property (nonatomic, retain) UIWindow *window;
    @property(nonatomic, readonly) RootViewController* viewController;
    
    @end

    Functions to add to AppController.mm

    #pragma mark - Google Play Game Services
    
    - (void)playServicesAuthenticate
    {
        NSLog(@"Authenticate");
        PlayGameSingleton::sharedInstance().authenticate();
    }
    
    - (BOOL)application:(UIApplication *)application
                openURL:(NSURL *)url
      sourceApplication:(NSString *)sourceApplication
             annotation:(id)annotation {
        return [GPPURLHandler handleURL:url sourceApplication:sourceApplication annotation:annotation];
    }
    
    - (void)finishedWithAuth:(GTMOAuth2Authentication *)auth error:(NSError *)error
    {
        NSLog(@"Finished with auth.");
        //if (error == nil && auth) {
        //NSLog(@"Success signing in to Google! Auth object is %@", auth);
        
        if (error.code == 0 && auth) {
            NSLog(@"Success signing in to Google! Auth object is %@", auth);
            
            // Tell your GPGManager that you're ready to go.
            [self startGoogleGamesSignIn];
            
        } else {
            NSLog(@"Failed to log into Google\n\tError=%@\n\tAuthObj=%@",error,auth);
        }
    }
    
    -(void)startGoogleGamesSignIn
    {
        // The GPPSignIn object has an auth token now. Pass it to the GPGManager.
        [[GPGManager sharedInstance] signIn:[GPPSignIn sharedInstance]
                         reauthorizeHandler:^(BOOL requiresKeychainWipe, NSError *error) {
                             // If you hit this, auth has failed and you need to authenticate.
                             // Most likely you can refresh behind the scenes
                             if (requiresKeychainWipe) {
                                 [[GPPSignIn sharedInstance] signOut];
                             }
                             //[[GPPSignIn sharedInstance] authenticate];
                         }];
    }
    

    Code to add to the didFinishLaunchingWithOptions function in AppController.mm

    // GOOGLE PLAY SERVICES
        
        GPPSignIn* signIn = [GPPSignIn sharedInstance];
        signIn.clientID = [NSString stringWithUTF8String:kClientID];
        signIn.scopes = [NSArray arrayWithObjects:
                         @"https://www.googleapis.com/auth/games",
                         @"https://www.googleapis.com/auth/appstate",
                         nil];
        signIn.language = [[NSLocale preferredLanguages] objectAtIndex:0];
        signIn.delegate = self;
        signIn.shouldFetchGoogleUserID = YES;
        
        
        [GPGManager sharedInstance].achievementUnlockedToastPlacement = kGPGToastPlacementBottom;
        
        if(!PlayGameSingleton::sharedInstance().isSignedIn())
        {
            //[NSThread detachNewThreadSelector:@selector(playServicesAuthenticate) toTarget:self withObject:nil];
        }
        
        // GOOGLE PLAY SERVICES END

    Frameworks to add to project:

    • AddressBook.framework
    • AssetsLibrary.framework
    • CoreData.framework
    • CoreLocation.framework
    • CoreMotion.framework
    • CoreTelephony.framework
    • CoreText.framework
    • Foundation.framework
    • MediaPlayer.framework
    • QuartzCore.framework
    • Security.framework
    • SystemConfiguration.framework
    • libc++.dylib
    • libz.dylib
    • GameController.framework (Only if supporting iOS 7+ otherwise follow the fix in the video)

    Gaz

  • Sonar Systems admin
    Likes 0


    This reply has been verified.
  • Ranzou
    Likes 1

    It seems the files in this tutorial, from https://github.com/cpinan/Cocos2dX_GooglePlayGamesServices are about 7 months old, so they include older versions of the Google Play Games framework for iOS. If you are using XCode 6.1, you will likely get linker errors while building the project. These errors are thrown because the GPG framework is ignored by XCode, because XCode is set up to accept arm64 frameworks, but not the arm32 that we are given (you can confirm it is only arm 32 with ‘lipo -info path/to/framework’). NB: if you choose to accept arm32 in XCode, you probably won’t be able to upload to the app store, so you likely need the 64-bit frameworks.

    If you wish, you can download the latest framework files from Google, here: https://developers.google.com/games/services/ios/quickstart and simply replace your old framework files. However, I have not tried to implement it, as the code is different, and my ObjC skills are lacking. If anyone wants to have a crack at it, please post your progress here. I may give it a go and will post updates here. Alternatively, does anyone know if there are more up-to-date 64-bit frameworks which won’t require much code changes?


    This reply has been verified.
  • Sonar Systems admin
    Likes 1

    We are aware of the issue but due to the lack of resources this isn’t easily fixable. We are working on a Cocos Helper which will include Game Center so it can be used very easily for iOS.


    This reply has been verified.

Login to reply