iOS SDK

This page will guide you through the integration of our iOS SDK into your app.

❗️

Caution!

This page documents a deprecated version, we highly recommend using the latest version documented here.

Account Set-Up and retrieving your API Key

Before we can get started with implementing the SDK, you should retrieve your API Key for your integration from the BitLabs Dashboard. If you haven't created an account yet, you can do so here and follow the instructions for the dashboard starting with Sign up & Set up.

Adding the SDK

Add a Podfile with BitLabs framework as a pod reference.

// Installing the SDK as pod reference
pod 'BitLabs'

Initiating the SDK

You will need to initiate the SDK before you can use it. You can do so with the following code.

var bitlabs: BitLabs?
bitlabs = BitLabs.Init(token: "YOUR_TOKEN", uid: "YOUR_USER_ID")

This is where you will need the API key from the dashboard, as you will need to replace "YOUR-TOKEN" with it. For "YOUR-USER-ID", you will need to dynamically insert the user id for each app user. Make sure the id used here is unique and that it does not change, as the user's profile will be stored under this id.

Using the SDK

Show BitLabs to the user

Now it's time to use the BitLabs SDK so that your users can start taking surveys. Call the .show() function to open the Offer Wall/Direct Link. BitLabs will show up and the user will see qualifications or surveys.

// Opening the Offerwall
bitlabs?.show(parent: self)

Theoretically, this is all you have to do. Anything below is optional but can improve the user experience.

.hasSurveys() - Check if there's something to do for the user

You can use .hasSurveys() to check if a survey is available for the user. This function will return true whenever there's a survey or a qualification question available for the user. If there's, it will return true.

// Checking for available surveys
bitlabs?.hasSurveys() { result in
	switch result {
	case true:
		debugPrint("Surveys available!")
  
  case false:
    debugPrint("No surveys available!")
    
  }
}

.onReward() - Client Side Callbacks

You can use .onReward() to check to receive callbacks to reward the user. We highly recommend using server-to-server callbacks instead! Please do not use this in apps where the user can withdraw real currency, as it might be exploitable.
However, if your app stores user data locally and does not sync with a server, this would be an option to still use BitLabs to reward your users.

bitlabs?.onReward(completionHandler: { payout in
	debugPrint("You earned: \(payout)")
})

.setTags() - Add Tags to receive in your callbacks

If you want to append additional information to our callback, for example information like "Premium User" or "New User", you can use .setTags()

It will append the information to the callbacks you receive.

bitlabs?.setTags(t: ["userType": "New", "isPremium": false])

Your next Step

You have now implemented BitLabs with your project. If you haven't done it already, it is time to configure server-to-server callbacks and the look and feel of your app.