For SWIFT
Do all steps from this article and then do the following steps:
- Initialization
- Purchases
- Special offers
- Push notifications
- Profile
- Converting
- Cross promotion ads
- A/B testing
- Profile's properties
Initialization
Step 3
Subscribe to onInitialized if you want to get information that the SDK has been initialized.
func onInitialized() { }
Subscribe to onConnected. onConnected is called after the GOW server response with dataReceived: true. If there was no response from the GOW server, there was an error during the request to the server or the game is offline, dataReceived is false.
'onConnected' callback is supported since 2.0.32 version of SDK.
func onConnected(_ dataReceived: Bool) { }
Call initialize method when you launch your app.
import GameOfWhales
...
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool
{
...
Bool debugLog = false;
GW.initialize( launchOptions, false);
GDPR NOTE: By default, the SDK uses advertisement ID (IDFA) as a user ID to send events to Game of Whales server. In order to work in a non-personal mode when a random value will be used as a user ID, the SDK should be initialized as follows:
let nonPersonal = true; let debugLog = true; GW.initialize(withGameKey: "YOU_GAME_KEY", launchOptions, debugLog, nonPersonal);
Purchases
Step 4
Purchases with verification on GOW server side
(only if you use in-app purchases)
Register a purchase with purchaseTransaction method.
func paymentQueue(_ queue: SKPaymentQueue, updatedTransactions transactions: [SKPaymentTransaction]) { for t in transactions if t.transactionState == SKPaymentTransactionState.purchased GW.purchaseTransaction(t, product: product!);
Check that iOS Bundle Identifier has been filled on Game Settings page before you will make a purchase.
Purchase without verification on GOW server side
The method is available since v.2.0.24 SDK version.
In order to send information about purchases without verification on Game of Whales side, call purchase method. For example:
let productID = "product_10"; let currency = "USD"; let price = 1.99; GW.purchase(productID, currency, price * 100);
Pay attention that all purchases received through purchase method (including refunds, restores, cheater's purchases) will increase the stats. So in order to have correct stats, a game developer should verify purchases on the game side and send the data only about legal purchases to Game of Whales system.
The SDK works with consumable products only.
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.
Step 5
If you want to use special offers, you need to implement some methods of GWDelegate protocol and call add method.
class ViewController: UIViewController, GWDelegate
...
override func viewWillAppear(_ animated: Bool) {
GWManager.add(self)
}
override func viewDidDisappear(_ animated: Bool) {
//remove self from delegates
GWManager.remove(self)
Step 6
Add the following methods:
func onPurchaseVerified(_ transactionID: String, state: String)
{
}
func specialOfferDisappeared(_ specialOffer: GWSpecialOffer)
{
}
func specialOfferAppeared(_ specialOffer: GWSpecialOffer)
{
}
func futureSpecialOfferAppeared(_ specialOffer: GWSpecialOffer)
{
}
func onPushDelivered(_ offer:GWSpecialOffer?, camp: String, title:String, message:String)
{
}
The verify state can be:
- GW_VERIFY_STATE_LEGAL - a purchase is normal.
- GW_VERIFY_STATE_ILLEGAL - a purchase is a cheater's.
- GW_VERIFY_STATE_UNDEFINED - GOW server couldn't define the state of a purchase.
Step 7
In order to receive a special offer call the following method:
let offer = GW.getSpecialOffer(productIdentifier);
if (offer != nil)
{ ...
A special offer can influence a product's price:
if (offer?.hasPriceFactor())!
{
price = Int(Float(price) * (offer?.priceFactor)!);
}
A special offer can also influence count (count of coins, for example) which a player receives by purchase:
if (offer?.hasCountFactor())!
{
coins = Int(Float(coins) * (offer?.countFactor)!);
}
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.
let str = offer.customValues.valueForKey("your_string") as? NString let number = offer.customValues.valueForKey("your_number") as? NSNumber let boolean = offer.customValues.valueForKey("your_bool") as? NSNumber
Notifications
Step 8
Enable the Push Notifications option in the Xcode.

Step 9
In order to send notifications from GOW server it is necessary to pass the token information to the server.
/FIREBASE
let token = FIRInstanceID.instanceID().token();
GW.registerDeviceToken(with: token!, provider:GW_PROVIDER_FCM);
//APN
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
GW.registerDeviceToken(with: deviceToken, provider: GW_PROVIDER_APN)
Step 10
To get information about a player's reaction on notifications add the following methods to AppDelegate:
func application(_ application: UIApplication,
didReceiveRemoteNotification userInfo: [AnyHashable : Any],
fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void)
{
GWManager.receivedRemoteNotification(userInfo, with: application, fetchCompletionHandler: completionHandler);
}
Step 11 (Only if notifications are shown inside your app by using the game's code)
In order to send the information to Game of Whales regarding a player's reaction on a notification (to increase push campaign's Reacted field) of an already started app call the following method:
func onPushDelivered(_ offer:GWSpecialOffer?, camp: String, title:String, message:String) {
//Show message and call:
GW.reactedRemoteNotification(withCampaign: camp);
Step 12
In order to enable or disable push notifications, use the following method:
GW.setPushNotificationsEnable(false);
In order to check notifications implementation send a test notification.
Profile
Step 13
You can send additional data about your players by using the profile method. profile method should be called if key parameters of your app or a player have changed.
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.
For example:
GW.profile(["coins":1000, "class":"wizard", "gender":true, "locatiom":"A"]);
Converting
Step 14
If you are going to use AI offers functionality you need to send to Game of Whales information about players' game activity by using converting method.
converting method should be called to show what exactly the player spent and what he got instead of spent resources. Read more...
For example:
Someone bought one bike_1 for 1000 coins and 50 gas. You should call the following method to reflect this operation in Game of Whales:
GW.converting(["coins":-1000, "gas":-50, "bike_1":1], place: "bank")
Another sample: someone bought a main pack for $5. It was in-app purchase with mainPack SKU. The pack included 100 coins and 1 bike. In order to send the data that the player got 100 coins and 1 bike after the purchase of mainPack to Game of Whales, the following Converting method should be called:
GW.converting(["coin":100, "bike":1, "mainPack":-1], place: "shop")
There are 2 additional methods that can be used instead of Converting method:
- consume -to show that a player spends a certain amount of one resource for the purchase of a quantity of another resource.
For example:
GW.consumeCurrency("coins", number:1000, sink:"gas", amount:50, place:"shop")
It means that someone spent 1000 "coins" for 50 "gas" in "shop".
- acquire - to show that a player acquires a certain amount of one resource and spends a quantity of another resource. The method can be used for in-app and in-game items. It's important to call acquire method after InAppPurchased.
For example:
GW.acquireCurrency("coins", amount:1000, source:sku, number:1, place:"bank")
It means that someone has acquired 1000 "coins" for 1 "sku" in "bank".
consume and acquire methods can be called when one resource is changed to another resource. In more complicated cases (for example, when one resource is spent for several types of resources) converting method should be called.
Сross promotion ads
It's supported since version 2.0.20 of SDK for iOS.
To handle the ads set in Game of Whales, you need to do some actions:
Step 15
Subscribe to the following events to get the information about the current state of the ads by using GWDelegate (the same as you do it on Step 6):
func onAdLoaded() { } func onAdLoadFailed() { } func onAdClosed() { }
Step 16
Start to load the ads at any place of your code (for example, during the launch of the game):
GW.loadAd()
Step 17
Add the following code to the part of your game where you want to show the ads:
if (GW.isAdLoaded()) GW.showAd() else GW.loadAd()
Profile's properties
Step 18
You can get some profile's properties defined on Game of Whales side via the SDK.
For example, you can get the profile's property group by using the following code:
let properties = GW.getProperties() if (properties["group"] != nil) { let group = properties.objectForKey("group") }
You can also receive the profile's group by using the special method:
let group = GW.getUserGroup()
A/B testing (experiments)
It's supported since version 2.0.29 of SDK for iOS.
Step 19
In order to start working with experiments, it's needed to add some methods:
- In order to confirm that the experiment payload settings have been applied and the player should take part in the experiment, it's needed to return true:
func canStart(_ experiment: GWExperiment) -> Bool { //Read experiment.payload, apply changes for experiment and return True if changes were applied return true; }
In order to check if there is an experiment at the start of the application, subscribe to onConnected callback. If the experiment exists, canStart will be called before onConnected.
- When the experiment is finished, OnExperimentEnded method will be called. You are able to remove all experiment changes or keep them for further work regardless of the experiment:
func onExperimentEnded(_ experiment: GWExperiment) { //Disable experiment changes or keep them }
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.
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.