Banner ads usually appear at the top or bottom of your app’s screen. Adding one to your app takes just a few lines of code.
Starting with MoPub SDK v5.8.0, you can specify a desired maximum ad size, and the MoPub SDK will request an ad for that size. To use that feature, ensure you are using the new ad request API as detailed below.
If your game is distributed on both iOS and Android, you only need to import the plugin once, but you must create different ad units for each platform:
#if UNITY_IOS adUnitId = "YOUR_IOS_AD_UNIT_ID"; #elif UNITY_ANDROID adUnitId = "YOUR_ANDROID_AD_UNIT_ID"; #endif MoPub.RequestBanner(adUnitId, position, maxAdSize);
Request a banner. Note that the
MoPub.CreateBanner(adUnitId, position)API has been deprecated as of MoPub SDK v5.8.0.
MoPub.RequestBanner(bannerAdUnit, position, maxAdSize);
Below is the complete list of recognized maximum ad sizes:
Width300Height50 Width300Height250 Width320Height50 Width336Height280 Width468Height60 Width728Height90 Width970Height90 Width970Height250 ScreenWidthHeight50 ScreenWidthHeight90 ScreenWidthHeight250 ScreenWidthHeight280
Note: Ad requests must be made on the main thread.
Show or hide the banner (this is optional; the banner is shown by default):
MoPub.ShowBanner (bannerAdUnit, true); // shows the banner MoPub.ShowBanner (bannerAdUnit, false); // hides the banner
Destroy the banner:
- Only create a banner ad view when you display it to the user.
- If the user navigates from a screen with a banner on it to a screen that does not have a banner, destroy or hide the banner.
- To be informed of the ad’s lifecycle events, visit the
MoPubManagerclass for the complete list of ad lifecycle callbacks to which you may subscribe.
How can we make this article better for you?
Last updated August 28, 2021
TWITTER, MOPUB, and the Bird logo are trademarks of Twitter, Inc. or its affiliates. All third party logos and trademarks included are the property of their respective owners.
© 2021 MoPub (a division of Twitter, Inc.)