Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.bytejourney.ios.interstitial;
- import static org.robovm.pods.google.mobileads.GADRequest.GADSimulatorID;
- import org.robovm.apple.foundation.NSArray;
- import org.robovm.apple.foundation.NSAutoreleasePool;
- import org.robovm.apple.foundation.NSError;
- import org.robovm.apple.uikit.UIApplication;
- import org.robovm.objc.block.VoidBlock2;
- import org.robovm.pods.google.mobileads.GADFullScreenContentDelegateAdapter;
- import org.robovm.pods.google.mobileads.GADFullScreenPresentingAd;
- import org.robovm.pods.google.mobileads.GADInterstitialAd;
- import org.robovm.pods.google.mobileads.GADMobileAds;
- import org.robovm.pods.google.mobileads.GADRequest;
- import com.badlogic.gdx.backends.iosrobovm.IOSApplication;
- import com.badlogic.gdx.backends.iosrobovm.IOSApplicationConfiguration;
- import com.bytejourney.ios.interstitial.MyGdxGame;
- public class IOSLauncher extends IOSApplication.Delegate implements AdsController {
- private IOSApplication iosApplication;
- @Override
- protected IOSApplication createApplication() {
- IOSApplicationConfiguration config = new IOSApplicationConfiguration();
- GADMobileAds.sharedInstance().getRequestConfiguration().setTestDeviceIdentifiers(new NSArray<>(GADSimulatorID()));
- GADMobileAds.sharedInstance().start(status -> {
- System.out.println("GADMobileAds started with status == " + status);
- });
- iosApplication = new IOSApplication(new MyGdxGame(this), config);
- return iosApplication;
- }
- public static void main(String[] argv) {
- NSAutoreleasePool pool = new NSAutoreleasePool();
- UIApplication.main(argv, null, IOSLauncher.class);
- pool.close();
- }
- @Override
- public void loadInterstitial() {
- String unitId = "ca-app-pub-3940256099942544/1033173712"; // test id admob
- GADRequest request = new GADRequest();
- GADInterstitialAd.load(unitId, request, new VoidBlock2<GADInterstitialAd, NSError>() {
- @Override
- public void invoke(GADInterstitialAd ad, NSError error) {
- if (error != null) {
- System.out.println("Failed to load ad due " + error);
- } else {
- ad.setFullScreenContentDelegate(new GADFullScreenContentDelegateAdapter(){
- @Override
- public void adDidDismissFullScreenContent(GADFullScreenPresentingAd ad) {
- super.adDidDismissFullScreenContent(ad);
- System.out.println("adDidDismissFullScreenContent");
- }
- @Override
- public void didFailToPresentFullScreenContent(GADFullScreenPresentingAd ad, NSError error) {
- System.out.println("didFailToPresentFullScreenContent " + error);
- }
- });
- ad.presentFromRootViewController(iosApplication.getUIViewController()); // show the interstitial ad
- }
- }
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement