Admob
import { Admob } from 'nitro-ui-admob'
Static members for the Google Mobile Ads SDK. The AdMob app ID is read from GADApplicationIdentifier in Info.plist on iOS and from the com.google.android.gms.ads.APPLICATION_ID meta-data in AndroidManifest.xml on Android.
| Member | Description |
|---|---|
initialize() | Starts the SDK early. Optional. |
setRequestConfiguration(configuration) | Replaces the settings of every later request. |
testAdUnitId(format) | Google's sample ad unit for a format. |
isShowingFullScreenAd | Whether a full-screen ad from this package is on screen. |
addOnAppForegroundListener(listener) | Listens for returns from the background. |
initialize
static initialize(): Promise<void>
Starts the Google Mobile Ads SDK. Later calls return the first result. Loading an ad starts the SDK too, so call this only to start early.
Rejects if the AdMob app ID is missing from the native app config. A failed start is not cached: the next call tries again.
setRequestConfiguration
static setRequestConfiguration(configuration: AdmobRequestConfiguration): void
Replaces the settings applied to every later ad request. Call it before loading ads, for example once consent is known. It works before and after initialize. Omitted fields use the SDK defaults, so each call replaces the whole configuration.
configuration is an AdmobRequestConfiguration. See the request configuration guide.
testAdUnitId
static testAdUnitId(format: AdmobFormat): string
Google's sample ad unit ID for format on the current platform. It always serves test ads. format is 'banner' | 'interstitial' | 'rewarded' | 'rewardedInterstitial' | 'appOpen'. The IDs are listed in platform differences.
isShowingFullScreenAd
static readonly isShowingFullScreenAd: boolean
Whether a full-screen ad from this package is on screen: shown, and not yet dismissed or failed to show.
addOnAppForegroundListener
static addOnAppForegroundListener(listener: () => void): AdmobListenerSubscription
Calls listener each time the app returns from the background. It is not called for the cold start. Call remove() on the returned AdmobListenerSubscription to unregister.
const subscription = Admob.addOnAppForegroundListener(() => console.log('foreground'))
subscription.remove()