admob.init()


Type Function

Return value none

See also admob.*


Overview

Initializes the extension. This function has to be called first, before using any other methods of the extension.

Syntax

admob.init(params)

params required

Table. Contains parameters for the call — see the next section for details.

Parameter Reference

The params table includes parameters for the call.

app_id required

String. Your app id, e.g. 'ca-app-pub-3940256099942544~3347511713'.

test optional

Boolean. If true, the test ads will be served. ALWAYS use test ads during the development.

listener optional

Function. The callback function which receives all admob events.

Example

-- App id and banner id for iOS and Android.
local app_id = {
	['iPhone OS'] = 'ca-app-pub-3940256099942544~1458002511',
	Android = 'ca-app-pub-3940256099942544~3347511713'
}
local banner_id = {
	['iPhone OS'] = 'ca-app-pub-3940256099942544/2934735716',
	Android = 'ca-app-pub-3940256099942544/6300978111'
}
local sysinfo = sys.get_sys_info()

local function listener(event)
	print('admob event type', event.type)
	print('admob event phase', event.phase)
	if event.phase == 'init' then -- Admob has been initialized, now it's safe to load a banner.
		admob.load{
			type = 'banner',
			id = banner_id[sysinfo.system_name],
			size = 'smart',
			position = 'bottom',
			keywords = {'puzzle', 'game'}
		}
	end
end

-- Init Admob with your app id for the current platform.
admob.init{
	app_id = app_id[sysinfo.system_name],
	test = true, -- ALWAYS use test ads, only disable when submitting to the stores.
	listener = listener
}