Skip to content

Game-of-whales/GOW-SDK-COCOS2D-CPP

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 

Repository files navigation

GameOfWhales Cocos2D SDK

Supported platforms: IOS

Supported lanuages: C++

Requirements: Cocos2D-X: 3.x+, iOS 7+

Changelog

2.0.14 (Jun 29, 2018)

ADDED

  • Custom data is supported for special offers.
  • The information about a device's locale is sent to Game of Whales.

MODIFIED

  • Push notification about special offer comes at the same time with the special offer (new parameter offer was added):
void onPushDelivered(const gameofwhales::SpecialOffer * so, const char* camp, const char* title, const char* message)
  • Static methods were added instead of shared methods.

Implementation Guide

SETUP

Download the latest sdk version from our server:

C++ Installation

Copy files

  1. from [GOW_COCOS_SDK]/Classes/ to [YOUR_PROJECT_FOLDLER]/Classes/
  2. 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 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 Android Bundle Identifier and Android Public License Key have 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 message to user when app in 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 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 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];
}

In order to check notifications implementation send a test notification.

Special Offers

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.

You need to do this chapter steps only if you want to use special offers from Game of Whales in your app.

To get information about special offers changes implement 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 offers custom data

It's possible to pass custom data to special offers. In order to get the data in 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.

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.