Adding Localytics in Cocos2d-x game for iOS - Plunge Interactive

Adding Localytics in Cocos2d-x game for iOS

How to include Localytics system in our iOS game

In first place, we need to go to http://www.localytics.com and sign in with our account.

After we create a new game, we obtain the ID Key for APP and the mirror to download the localytics SDK with the classes and files to add with our project.

 

After this, we need to add the files LocalyticsDatabase.h/.cpp , LocalyticsSession.h/.cpp , LocalyticsUploader.h/.cpp and WebserviceConstants.h in our Xcode project. Something like this:

 

Now we click on our xCode project, select the “Build Phases” tab, click on “Link Binary With Libraries” and “Add item” (the plus symbol on the top of drop down menu):

Enter “libs” and add libz.dylib. The same with “libsqlite3” adding libsqlite3.dylib .

Now is time to make source code (not much).

First, import LocalyticsSession.h in your application’s delegate file (in my case AppController.mm) and go to the didFinishLaunching or didFinishLaunching (depend of the newer version that you have). Copy this:

//Open Localytics session. YOUR_ID_APP that you obtained in previously step.
[[LocalyticsSession sharedLocalyticsSession] startSession:@"YOUR_ID_APP"];

In the same file, go to applicationWillResignActiveand add:

//If the screen is locked more than 15 seconds the Localytics session is closed
[[LocalyticsSession sharedLocalyticsSession] close];
[[LocalyticsSession sharedLocalyticsSession] upload];

[Optional]

In applicationDidBecomeActive:

//When user unlocks screen the Localytics session is resumed or created (if screen is locked more than 15 seconds)
[[LocalyticsSession sharedLocalyticsSession] resume];
[[LocalyticsSession sharedLocalyticsSession] upload];

In applicationDidEnterBackground:

//Closing Localytics session
[[LocalyticsSession sharedLocalyticsSession] close];
[[LocalyticsSession sharedLocalyticsSession] upload];

[Optional]

In applicationWillEnterForeground:

//Reloading Localytics data if application don't upload anything in 15 seconds
[[LocalyticsSession sharedLocalyticsSession] resume];
[[LocalyticsSession sharedLocalyticsSession] upload];

In applicationWillTerminate:

//Closing Localytics session
[[LocalyticsSession sharedLocalyticsSession] close];
[[LocalyticsSession sharedLocalyticsSession] upload];

After this, our app can open/close/resume/upload  data to Localytics session. If you want more info go to documentation http://www.localytics.com/docs/iphone-integration 

Maybe you are interested in tagging events on app to share to to localytics. To do this, only copy this code line within your event:

[[LocalyticsSession sharedLocalyticsSession] tagEvent:@"Your interesting Event"];

This site uses cookies to store information on your computer. Some cookies on this site are essential, and the site won't work as expected without them. Read more about them

ACCEPT