This RoboPod requires you to download and add the native 3rd party frameworks manually:
- Download the SDK Zip file from https://developers.google.com/admob/ios/download
- Unzil all the contents (several .framework files) in your iOS project's
libs/
folder - Add the missing frameworks to your
robovm.xml
<config>
...
<frameworkPaths>
<path>libs</path>
</frameworkPaths>
<frameworks>
...
<framework>GoogleAppMeasurement</framework>
<framework>GoogleMobileAds</framework>
<framework>GoogleUtilities</framework>
<framework>nanopb</framework>
</frameworks>
</config>
Add the following dependency to your build.gradle
:
dependencies {
... other dependencies ...
compile "com.mobidevelop.robovm:robopods-google-mobile-ads-ios:$robopodsVersion"
}
Add the following dependency to your pom.xml
:
<dependency>
<groupId>com.mobidevelop.robovm</groupId>
<artifactId>robopods-google-mobile-ads-ios</artifactId>
<version>${robopods.version}</version>
</dependency>
Admob reports SDK crashes by default. This will make problems if you intend to use a different crash reporting service, as you can only have one (1!) crash reporting service in your app.
To disable Admob's crash reporting add the following code to your application's entry point:
GADMobileAds.disableSDKCrashReporting();
- Make sure you have setup your app in your Admob dashboard.
- Check your logs for any errors, like network failures.
- Load and display advertisements in your app: Link
- Read the official Google Mobile Ads iOS documentation: Link
Setup and display ads.
To display any ad you have to create a GADRequest
first.
You can specify various user information for better ad targeting and enable test ads for specific device ids.
GADRequest request = new GADRequest();
// Display test ads on the simulator.
request.setTestDevices(Arrays.asList(GADRequest.getSimulatorID()));
...
Create a new instance of GADInterstitial
and store it as a member variable:
adInterstitial = new GADInterstitial("AD_UNIT_ID");
Change AD_UNIT_ID
with the one you setup in your Admob dashboard.
If you setup Google Mobile Ads with a configuration file you can get the default interstitial id:
String interstitialId = GGLContextMobileAds.getSharedInstance().getConfiguration().getInterstitialAdUnitID();
You can optionally listen for certain events by setting the ad delegate:
adInterstitial.setDelegate(new GADInterstitialDelegateAdapter() {
@Override
public void didReceiveAd(GADInterstitial ad) {
// Ad received.
}
...
});
To be able to display the ad later, you have to load the ad first. Do this as early as possible.
adInterstitial.loadRequest(request);
Create and pass a new GADRequest
object as explained in an earlier section.
To display the interstitial use the following code:
if (adInterstitial.isReady()) {
adInterstitial.present(viewController);
} else {
adInterstitial.loadRequest(request);
}
You have to pass a UIViewController
when presenting the ad. Ideally you should setup the interstitial
in a view controller subclass and specify this
.
If you're developing a libGDX game you can just use the root view controller of the application:
UIViewController viewController = UIApplication.getSharedApplication().getKeyWindow().getRootViewController();
If you want to show another interstitial after that one is shown, you have to create a new GADInterstitial
.
Never show the same GADInterstitial
twice!
The best place to recreate the interstitial is in the didDismissScreen
delegate callback:
@Override
public void didDismissScreen(GADInterstitial ad) {
interstitial = createAndLoadInterstitial(); // As described before.
}
Create a new instance of GADBannerView
, set the ad unit id and store it as a member variable:
bannerView = new GADBannerView();
bannerView.setAdUnitID("AD_UNIT_AD");
Change AD_UNIT_ID
with the one you setup in your AdMob dashboard.
If you setup Google Mobile Ads with a configuration file you can get the default banner id:
String bannerId = GGLContextMobileAds.getSharedInstance().getConfiguration().getBannerAdUnitID();
Alternatively you can add the banner as an outlet and add the banner view to your storyboard in Interface Builder.
@IBOutlet
private GADBannerView bannerView;
See the Quick Start guide how to add the banner in interface builder: Link
You can optionally listen for certain events by setting the ad delegate:
bannerView.setDelegate(new GADBannerViewDelegateAdapter() {
@Override
public void didReceiveAd(GADBannerView bannerView) {
// Did receive ad.
}
});
To be able to display the ad later, you have to load the ad first. Do this as early as possible.
bannerView.loadRequest(request);
Create and pass a new GADRequest
object as explained in an earlier section.
To display the ad you have to add it to your view hierarchy (skip this step if you added the banner to your storyboard):
viewController.getView().addSubview(bannerView);
Modify the frame of the banner view to change it's position.
Add the code for interstitials and banners to your app.
Run the app and display the ads. If you set correct test device ids when creating your GADRequest
objects
you should always see an ad.
- Make sure you have setup your app in your Admob dashboard.
- Make sure you have create ad units for your app in your Admob dashboard.
- Check your logs for any errors, like network failures.
- Read the official Google Mobile Ads iOS documentation: Link