/
gecreator
/
defold-admob-api
Обзор
Документация
Войти
/
gecreator
/
defold-admob-api
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
admob.lua
281 строка
12 KB
gecreator
init
27 фев 2026, 13:37
Верифицирован
27 фев 2026, 13:37
c5cc8aa
Код
Авторство
О чём код?
---@meta admob ---@class admob admob = {} ---@alias admob.message_id integer ---@alias admob.event integer ---@alias admob.banner_size integer ---@alias admob.banner_position integer ---@alias admob.max_ad_content_rating integer ---@alias admob.idfa_event integer ---Initialize the Mobile Ads SDK. ---Warning: If you need to obtain consent from users in the European Economic Area (EEA), set ---any request-specific flags, or otherwise take action before loading ads, ensure you do so ---before initializing the Mobile Ads SDK. ---Original docs ---[Android](https://developers.google.com/admob/android/quick-start#initialize_the_mobile_ads_sdk), ---[iOS](https://developers.google.com/admob/ios/quick-start#initialize_the_mobile_ads_sdk) function admob.initialize() end ---Sets a callback function for receiving events from the SDK. Call `admob.set_callback(nil)` ---to remove callback ---@param callback fun(self: any, message_id: admob.message_id, message: admob.message)|nil Callback function that is executed on any event in the SDK. function admob.set_callback(callback) end ---Sets user privacy preferences (must be called before `admob.initialize()`). ---Original docs ---[Android](https://developers.google.com/admob/android/ccpa), ---[iOS](https://developers.google.com/admob/ios/ccpa) ---@param bool boolean function admob.set_privacy_settings(bool) end ---Display the App Tracking Transparency authorization request for accessing the IDFA. ---Original docs ---[iOS](https://developers.google.com/admob/ios/ios14#request) function admob.request_idfa() end ---Show Ad Inspector. This is an in-app overlay that enables authorized devices to perform ---realtime analysis of test ad requests directly within a mobile app. ---Ad Inspector only launces on [test devices](https://support.google.com/admob/answer/9691433). ---Original docs ---[Android](https://developers.google.com/admob/android/ad-inspector), ---[iOS](https://developers.google.com/admob/ios/ad-inspector) function admob.show_ad_inspector() end ---Starts loading an AppOpen Ad, can only be called after `admob.MSG_INITIALIZATION` event ---Original docs ---[Android](https://developers.google.com/admob/android/app-open), ---[iOS](https://developers.google.com/admob/ios/app-open) ---@param ad_unit_id string Ad unit ID, for test ads use on Android `"ca-app-pub-3940256099942544/9257395921"`, or on iOS `"ca-app-pub-3940256099942544/5575463023"` function admob.load_appopen(ad_unit_id) end ---Shows loaded AppOpen Ad, can only be called after `admob.EVENT_LOADED` ---Original docs ---[Android](https://developers.google.com/admob/android/app-open), ---[iOS](https://developers.google.com/admob/ios/app-open) function admob.show_appopen() end ---Checks if AppOpen Ad is loaded and ready to show ---Original docs ---[Android](https://developers.google.com/admob/android/app-open), ---[iOS](https://developers.google.com/admob/ios/app-open) ---@return boolean is_ready function admob.is_appopen_loaded() end ---Starts loading an Interstitial Ad, can only be called after `admob.MSG_INITIALIZATION` event ---Original docs ---[Android](https://developers.google.com/admob/android/interstitial-fullscreen), ---[iOS](https://developers.google.com/admob/ios/interstitial) ---@param ad_unit_id string Ad unit ID, for test ads use on Android `"ca-app-pub-3940256099942544/1033173712"`, or on iOS `"ca-app-pub-3940256099942544/4411468910"` function admob.load_interstitial(ad_unit_id) end ---Shows loaded Interstitial Ad, can only be called after `admob.EVENT_LOADED` ---Original docs ---[Android](https://developers.google.com/admob/android/interstitial-fullscreen), ---[iOS](https://developers.google.com/admob/ios/interstitial) function admob.show_interstitial() end ---Checks if Interstitial Ad is loaded and ready to show ---Original docs ---[Android](https://developers.google.com/admob/android/interstitial-fullscreen), ---[iOS](https://developers.google.com/admob/ios/interstitial) ---@return boolean is_ready function admob.is_interstitial_loaded() end ---@class admob.rewarded_options ---@field user_id? string A unique identifier assigned to each user. ---@field custom_data? string Custom Data attached to server-side reward callbacks. ---Starts loading a Rewarded Ad, can only be called after `admob.MSG_INITIALIZATION` event ---Original docs ---[Android](https://developers.google.com/admob/android/rewarded-fullscreen), ---[iOS](https://developers.google.com/admob/ios/rewarded-ads) ---@param ad_unit_id string Ad unit ID, for test ads use on Android `"ca-app-pub-3940256099942544/1712485313"`, or on iOS `"ca-app-pub-3940256099942544/4411468910"` ---@param options? admob.rewarded_options ServerSideVerificationOptions function admob.load_rewarded(ad_unit_id, options) end ---Shows loaded Rewarded Ad, can only be called after `admob.EVENT_LOADED` ---Original docs ---[Android](https://developers.google.com/admob/android/rewarded-fullscreen), ---[iOS](https://developers.google.com/admob/ios/rewarded-ads) function admob.show_rewarded() end ---Checks if Rewarded Ad is loaded and ready to show ---Original docs ---[Android](https://developers.google.com/admob/android/rewarded-fullscreen), ---[iOS](https://developers.google.com/admob/ios/rewarded-ads) ---@return boolean is_ready function admob.is_rewarded_loaded() end ---Starts loading a Rewarded Interstitial Ad, can only be called after `admob.MSG_INITIALIZATION` event ---Original docs ---[Android](https://developers.google.com/admob/android/rewarded-interstitial#load_an_ad), ---[iOS](https://developers.google.com/admob/ios/rewarded-interstitial#load_an_ad) ---@param ad_unit_id string Ad unit ID, for test ads use on Android `"ca-app-pub-3940256099942544/5354046379"`, or on iOS `"ca-app-pub-3940256099942544/6978759866"` function admob.load_rewarded_interstitial(ad_unit_id) end ---Shows loaded Rewarded Interstitial Ad, can only be called after `admob.EVENT_LOADED` ---Original docs ---[Android](https://developers.google.com/admob/android/rewarded-interstitial#show_the_ad), ---[iOS](https://developers.google.com/admob/ios/rewarded-interstitial#display_the_ad_and_handle_the_reward_event) function admob.show_rewarded_interstitial() end ---Checks if Rewarded Interstitial Ad is loaded and ready to show ---Original docs ---[Android](https://developers.google.com/admob/android/rewarded-interstitial), ---[iOS](https://developers.google.com/admob/ios/rewarded-interstitial) ---@return boolean is_ready function admob.is_rewarded_interstitial_loaded() end ---Starts loading a Banner Ad, can only be called after `admob.MSG_INITIALIZATION` event ---Original docs ---[Android](https://developers.google.com/admob/android/banner), ---[iOS](https://developers.google.com/admob/ios/banner) ---@param ad_unit_id string Ad unit ID, for test ads use on Android `"ca-app-pub-3940256099942544/6300978111"`, or on iOS `"ca-app-pub-3940256099942544/2934735716"` ---@param size? admob.banner_size Requested Banner Ad size, possible values: `admob.SIZE_ADAPTIVE_BANNER` (default), `admob.SIZE_BANNER`, `admob.SIZE_FLUID`, `admob.SIZE_FULL_BANNER`, `admob.SIZE_LARGE_BANNER`, `admob.SIZE_LEADEARBOARD`, `admob.SIZE_MEDIUM_RECTANGLE`, `admob.SIZE_SMART_BANNER`, `admob.SIZE_LARGE_ADAPTIVE_BANNER` function admob.load_banner(ad_unit_id, size) end ---Shows loaded Banner Ad, can only be called after `admob.EVENT_LOADED` ---Original docs ---[Android](https://developers.google.com/admob/android/banner), ---[iOS](https://developers.google.com/admob/ios/banner) ---@param position? admob.banner_position Banner Ad position, possible values: `admob.POS_NONE` (default), `admob.POS_TOP_LEFT`, `admob.POS_TOP_CENTER`, `admob.POS_TOP_RIGHT`, `admob.POS_BOTTOM_LEFT`, `admob.POS_BOTTOM_CENTER`, `admob.POS_BOTTOM_RIGHT`, `admob.POS_CENTER` function admob.show_banner(position) end ---Sets a maximum ad content rating. AdMob ads returned for your app will have a content rating at or below that level. ---Original docs ---[Android](https://developers.google.com/admob/android/targeting#ad_content_filtering), ---[iOS](https://developers.google.com/admob/ios/targeting#ad_content_filtering) ---@param max_ad_rating admob.max_ad_content_rating Max Ad Rating, possible values: `admob.MAX_AD_CONTENT_RATING_G`, `admob.MAX_AD_CONTENT_RATING_PG`, `admob.MAX_AD_CONTENT_RATING_T`, `admob.MAX_AD_CONTENT_RATING_MA` function admob.set_max_ad_content_rating(max_ad_rating) end ---Temporarily hides Banner Ad, banner can be shown again using `admob.show_banner()` ---Original docs ---[Android](https://developers.google.com/admob/android/banner), ---[iOS](https://developers.google.com/admob/ios/banner) function admob.hide_banner() end ---Checks if Banner Ad is loaded and ready to show ---Original docs ---[Android](https://developers.google.com/admob/android/banner), ---[iOS](https://developers.google.com/admob/ios/banner) ---@return boolean is_ready function admob.is_banner_loaded() end ---Hides and unloads Banner Ad (needs to call `admob.load_banner()` later to show Banner Ad) ---Original docs ---[Android](https://developers.google.com/admob/android/banner), ---[iOS](https://developers.google.com/admob/ios/banner) function admob.destroy_banner() end ---@class admob.message ---@field event admob.event ---@field code? number The error code (if an error occurred or `nil` otherwise) ---@field message? string The error message (if an error occurred or `nil` otherwise) ---@field amount? number The reward amount (for rewarded ads) ---@field type? string The reward type (for rewarded ads) ---@field error? string Error message (for JSON errors) ---@field height? number Banner height in pixels ---@field width? number Banner width in pixels ---@type admob.message_id admob.MSG_INITIALIZATION = nil ---@type admob.message_id admob.MSG_INTERSTITIAL = nil ---@type admob.message_id admob.MSG_REWARDED = nil ---@type admob.message_id admob.MSG_BANNER = nil ---@type admob.message_id admob.MSG_IDFA = nil ---@type admob.message_id admob.MSG_REWARDED_INTERSTITIAL = nil ---@type admob.message_id admob.MSG_APPOPEN = nil ---@type admob.event admob.EVENT_CLOSED = nil ---@type admob.event admob.EVENT_FAILED_TO_SHOW = nil ---@type admob.event admob.EVENT_OPENING = nil ---@type admob.event admob.EVENT_FAILED_TO_LOAD = nil ---@type admob.event admob.EVENT_LOADED = nil ---@type admob.event admob.EVENT_NOT_LOADED = nil ---@type admob.event admob.EVENT_EARNED_REWARD = nil ---@type admob.event admob.EVENT_COMPLETE = nil ---@type admob.event admob.EVENT_CLICKED = nil ---@type admob.event admob.EVENT_DESTROYED = nil ---@type admob.event admob.EVENT_JSON_ERROR = nil ---@type admob.event admob.EVENT_IMPRESSION_RECORDED = nil ---@type admob.idfa_event admob.EVENT_STATUS_AUTHORIZED = nil ---@type admob.idfa_event admob.EVENT_STATUS_DENIED = nil ---@type admob.idfa_event admob.EVENT_STATUS_NOT_DETERMINED = nil ---@type admob.idfa_event admob.EVENT_STATUS_RESTRICTED = nil ---@type admob.idfa_event admob.EVENT_NOT_SUPPORTED = nil ---@type admob.banner_size admob.SIZE_ADAPTIVE_BANNER = nil ---@type admob.banner_size admob.SIZE_LARGE_ADAPTIVE_BANNER = nil ---@type admob.banner_size admob.SIZE_BANNER = nil ---@type admob.banner_size admob.SIZE_FLUID = nil ---@type admob.banner_size admob.SIZE_FULL_BANNER = nil ---@type admob.banner_size admob.SIZE_LARGE_BANNER = nil ---@type admob.banner_size admob.SIZE_LEADEARBOARD = nil ---@type admob.banner_size admob.SIZE_MEDIUM_RECTANGLE = nil ---@type admob.banner_size admob.SIZE_SMART_BANNER = nil ---@type admob.banner_position admob.POS_NONE = nil ---@type admob.banner_position admob.POS_TOP_LEFT = nil ---@type admob.banner_position admob.POS_TOP_CENTER = nil ---@type admob.banner_position admob.POS_TOP_RIGHT = nil ---@type admob.banner_position admob.POS_BOTTOM_LEFT = nil ---@type admob.banner_position admob.POS_BOTTOM_CENTER = nil ---@type admob.banner_position admob.POS_BOTTOM_RIGHT = nil ---@type admob.banner_position admob.POS_CENTER = nil ---@type admob.max_ad_content_rating admob.MAX_AD_CONTENT_RATING_G = nil ---@type admob.max_ad_content_rating admob.MAX_AD_CONTENT_RATING_PG = nil ---@type admob.max_ad_content_rating admob.MAX_AD_CONTENT_RATING_T = nil ---@type admob.max_ad_content_rating admob.MAX_AD_CONTENT_RATING_MA = nil