Initialize the SDK
You need to initialize the adjoe SDK before you can use any of its features. To do this, call Adjoe.Init(sdkHash, options, success, failure). when your app is starting. The initialization will run asynchronously in the background and notify you when it is finished by invoking one of the callback methods. After one successful initialization all following calls to Adjoe.Init will immediately invoke the success callback until your app is removed from the heap. The SDK initialization should be started as soon as possible after the app starts to make sure that all adjoe features are available when you want to use them.

Best practices for the SDK initialization:

    Initialize early: You should initialize the SDK as soon as possible after your app starts to make sure that all adjoe features are available when you want to use them.
    Initialize regularly: For the best user experience, we highly recommend to call this method every time your app comes to the foreground. This should not be noticeable in your app's performance.
    Initialization triggers: Good places to call this method are the app start and resume.
1
local Adjoe = class("Adjoe", cc.load("adjoe").Adjoe)
2
3
function MyApp:onCreate()
4
...
5
Adjoe.Init("sdkHash", options,
6
function ()
7
-- the adjoe plugin was initialized successfully
8
end,
9
function (msg)
10
-- an error occurred while initializing the adjoe plugin.
11
end
12
)
13
...
14
end
Copied!
The parameters to this call are as follows:
    String sdkHash: You adjoe API key.
    Table options: A table for passing additional values to the initialization of adjoe. Currently the following options are supported:
      String UserID: A custom identifier that you wish to assign to this user. If you don't have an identifier for your user already, the adjoe SDK will generate one.
      Table AdjoeParams: A table containing User Acquisition and offerwall placement parameters.
If you do not want to use the options, you can passnil in place of the table.
If you want to use S2S payout, you have to set the user id in order to match the payout to your user.
Adjoe Parameters
You can pass additional UA and placement parameters when you initialize the SDK
1
local params = Adjoe.NewAdjoeParams()
2
:SetUANetwork("network")
3
:SetUAChannel("channel")
4
:SetUASubPublisherCleartext("SubPublisherCleartext")
5
:SetUASubPublisherEncrypted("SubPublisherEncrypted")
6
:SetPlacement("Placement")
7
8
local options = Adjoe.NewOptions()
9
:SetUserID("userId")
10
:SetAdjoeParams(params)
11
12
Adjoe.Init("sdkHash", options, success, failure)
13
Copied!

The IsInitialized method

To check whether the SDK is initialized you can call Adjoe.IsInitialized(). This will return true if the SDK is initialized and false otherwise. However, you should not condition calling Init on the result of IsInitialized because the SDK will do some checks on its own. You should not do something like the following as it can lead to bad user experience:
1
function MyApp:onCreate()
2
if not Adjoe.IsInitialized() then
3
Adjoe.Init(sdkHash, options, successCallback, errorCallback);
4
end
5
end
Copied!
Instead, just call Init without checking for IsInitialized. You can however use IsInitialized e.g. for debugging or to check whether the SDK is initialized before calling other methods of the SDK like RequestRewards.
Last modified 7mo ago
Copy link