Cocos2D SDK
Requirements
Supported platforms: IOS
Supported lanuages: C++
Requirements: Cocos2D-X: 3.x+, iOS 7+
SETUP
Download the latest sdk version from our server.
C++ Installation
Copy files
- from [GOW_COCOS_SDK]/Classes/ to [YOUR_PROJECT_FOLDLER]/Classes/
- from [GOW_COCOS_SDK]/proj.ios_mac/ to [YOUR_PROJECT_FOLDLER]/proj.ios_mac/
Configure XCODE
Add [YOUR_PROJECT_FOLDLER]/Classes/ to your project.

Add [YOUR_PROJECT_FOLDLER]/proj.ios_mac/GameOfWhales.framework to your project.

In Info.plist set App Transport Security Settings/Allow Arbitrary Loads option to YES.

Code integration
C++
Initialize SDK with your game key.
#include "GameOfWhales/GameOfWhales.h" ... bool debugLogging = true; gameofwhales::initialize("YOUR_GAME_KEY", debugLogging);
Add SDK's listener:
class HelloWorld : public gameofwhales::Listener bool HelloWorld::init() { gameofwhales::addListener(this);
Implement needed listener's methods:
void specialOfferAppeared(const SpecialOffer& offer) override; void specialOfferDisappeared(const SpecialOffer& offer) override; void onPushDelivered(const gameofwhales::SpecialOffer * so, const char* camp, const char* title, const char* message) override; void onPurchaseVerified(const char* transactionID, gameofwhales::PURCHASE_STATE state) override;
The purchase state can be:
- VERIFY_STATE_LEGAL - a purchase is normal.
- VERIFY_STATE_ILLEGAL - a purchase is a cheater's.
- VERIFY_STATE_UNDEFINED - GOW server couldn't define the state of a purchase.
Game Events
Send information about IAPs, for example, by using BOXSDK:
void HelloWorld::onSuccess(sdkbox::Product const& p) { std::string receiptJSON = gameofwhales::buildReceipt(gameofwhales::STORE_APPSTORE, p.transactionID.c_str(), p.receiptCipheredPayload.c_str()); const char * sku = p.id.c_str(); float price = p.priceValue; const char * currencyCode = p.currencyCode.c_str(); const char * transactionID = p.transactionID.c_str(); gameofwhales::inAppPurchased(sku, price, currencyCode, transactionID, receiptJSON.c_str());
Check that iOS Bundle Identifier has been filled on Game Settings page before you will make a purchase.
Send user data, for example:
gameofwhales::json::JSON data; data["coins"] = _playerData.getCoins(); data["gender"] = _playerData.getGender(); data["location"] = _playerData.getLocation(); data["class"] = _playerData.getSpeciality(); gameofwhales::profile(data.dump().c_str());
If you send more than 3000 properties, Game of Whales will sort all properties alphabetically and will save only the first 3000.
If the length of a string-type property is more than 64 characters, Game of Whales will save only the first 64 characters.
Send information about user currency consuming, for example:
const char * currency = "coins"; int itemCost = 1000; const char * itemName = "item1"; int amount = 1; const char * place = "shop"; gameofwhales::consume("currency, itemCost, itemName, amount, place);
It means that someone spent 1000 "coins" for 1 "item1" in "shop".
Send information about user currency obtainment, for example:
const char * currency = "coins"; int value = 5000; const char * itemName = "yourgame.product.iap"; int amount = 1; const char * place = "bank"; gameofwhales::acquire(currency, value, itemName, amount, place);
It means that someone has acquired 5000 "coins" for 1 "yourgame.product.iap" in "bank".
Push notifications
You need to do this chapter steps only if you want to use push notifications in your app.
In order to request permission for push notifications, add code to your AppDelegate class, for example:
UNAuthorizationOptions authOptions = UNAuthorizationOptionAlert | UNAuthorizationOptionSound | UNAuthorizationOptionBadge; [[UNUserNotificationCenter currentNotificationCenter] requestAuthorizationWithOptions:authOptions completionHandler:^(BOOL granted, NSError * _Nullable error) { if(!error){ dispatch_async(dispatch_get_main_queue(), ^{ [[UIApplication sharedApplication] registerForRemoteNotifications]; }); } }];
Show a message to the user when the app in the foreground and send "reacted" event:
void onPushDelivered(const char* camp, const char* title, const char* message) { //show message box and then call: gameofwhales::pushReacted(camp); }
To register device token, add the next code to your AppDelegate class:
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken { [[GW shared] registerDeviceTokenWithData: deviceToken provider:GW_PROVIDER_APN]; }
In order to provide information about received notifications, add the next code to your AppDelegate class:
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult result))completionHandler { [[GW shared] receivedRemoteNotification:userInfo withApplication:application fetchCompletionHandler:completionHandler]; }
Special Offers
You need to do this chapter steps only if you want to use special offers from Game of Whales in your app.
Before any product can be used in a special offer it has to be bought by someone after SDK has been implemented into the game. Please make sure your game has at least one purchase of the product that is going to be used in the special offer. If you want to create a special offer for in game resource, please, make sure your game has at least one converting event with the appropriate resource.
To get information about special offers changes implement the next listener's methods:
void specialOfferAppeared(const SpecialOffer& offer) override; void specialOfferDisappeared(const SpecialOffer& offer) override;
To receive information about special offer for product call gameofwhales::getSpecialOffer method:
//buying some product const char* productID = "item1"; float price = 1000; float count = 10; const gameofwhales::SpecialOffer * offer = gameofwhales::getSpecialOffer(productID); if (offer && !offer->isExpiried()) { if (offer->hasPriceFactor() ) { //change price for product price *= offer->priceFactor; } if (offer->hasCountFactor()) { count *= offer->countFactor; } ... }
Special offer custom data
It's possible to pass custom data to special offers. In order to get the data in the game's side, use customValues parameter of SpecialOffer class.
string str = offer.customValues["your_string"]; int number = atoi(offer.customValues["your_number"].c_str()); bool boolean = atoi(offer.customValues["your_bool"].c_str());
You can find an example of using the SDK here.
Pay attention that the SDK sends immediately only "login" and "purchase" events. Other events ("token", "profile", etc) are collected in the bulk and sent time by time.
Run your app. The information about it began to be collected and displayed on the dashboard. In a few days, you will get data for analyzing.
This article includes the documentation for Game of Whales Cocos2D SDK. You can find information about other SDKs in documentation about Game of Whales.