Skip to content

Latest commit

 

History

History
 
 

ios-ads

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

Flurry Advertising iOS

Sample app

Link

Install Instructions

3rd party native framework

This RoboPod requires you to download and add the native 3rd party library manually:

  1. Download the SDK for iOS from https://dev.flurry.com
  2. Put the libFlurryAds_X.X.X.a file in your iOS project's libs/ folder
  3. Add the following to your robovm.xml
<config>
    ...
    <libs>
        <lib>libs/libFlurryAds_X.X.X.a</lib>
    </libs>
</config>

Change X.X.X with the version number of the library.

Gradle

Add the following dependency to your build.gradle:

dependencies {
   ... other dependencies ...
   compile "com.mobidevelop.robovm:robopods-flurry-ios-ads:$robopodsVersion"
}

Maven

Add the following dependency to your pom.xml:

<dependency>
   <groupId>com.mobidevelop.robovm</groupId>
   <artifactId>robopods-flurry-ios-ads</artifactId>
   <version>${robopods.version}</version>
</dependency>

Code Examples

SDK setup

Before you can display any ads, you have to setup the SDK.

Start Flurry in your app

Add the following code to your application's entry point, typically didFinishLaunching() in your app delegate.

Flurry.startSession("API_KEY");

Change the API_KEY with your key that you can find in your Flurry dashboard.

Enable debug logging

When setting up Flurry it's very helpful to get logs.
Add the following code before starting Flurry:

Flurry.setDebugLogEnabled(true);
Flurry.setLogLevel(FlurryLogLevel.All); // Adjust level to your needs.

...

Flurry.startSession("API_KEY");

Note: Don't forget to disable debug logging when you release your app!

Having trouble?
  • Make sure you have setup an app in your Flurry dashboard and specified the correct API_KEY.
  • Check your logs for any errors, like network failures.
Next steps
  • Load and display advertisements in your app: Link
  • Read the official Flurry documentation: Link

Display ads

Cache and display ads.

Interstitials

Create a new instance of FlurryAdInterstitial and store it as a member variable:

adInterstitial = new FlurryAdInterstitial("AD_SPACE_NAME");

Change AD_SPACE_NAME with the one you setup in your Flurry dashboard.

You can optionally listen for certain events by setting the ad delegate:

adInterstitial.setAdDelegate(new FlurryAdInterstitialDelegateAdapter() {
    @Override
    public void didFetchAd(FlurryAdInterstitial interstitialAd) {
        // You can choose to present the ad as soon as it is received.
        // adInterstitial.present(viewController);
    }

    @Override
    public void didDismiss(FlurryAdInterstitial interstitialAd) {
        // Ideal time to fetch a new ad.
        adInterstitial.fetchAd();
    }

    @Override
    public void didFail(FlurryAdInterstitial interstitialAd, FlurryAdError adError, NSError errorDescription) {
        // Ideal time to fetch a new ad.
        adInterstitial.fetchAd();
    }
});

To be able to display an ad later, you have to fetch an ad first. Do this as early as possible.

adInterstitial.fetchAd();

To display the interstitial use the following code:

if (adInterstitial.isReady()) {
    adInterstitial.present(viewController);
} else {
    adInterstitial.fetchAd();
}

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();

Banners

Create a new instance of FlurryAdBanner and store it as a member variable:

adBanner = new FlurryAdBanner("AD_SPACE_NAME");

Change AD_SPACE_NAME with the one you setup in your Flurry dashboard.

You can optionally listen for certain events by setting the ad delegate:

adBanner.setAdDelegate(new FlurryAdBannerDelegateAdapter() {
    @Override
    public void didFetchAd(FlurryAdBanner bannerAd) {
        // If you used fetchAd(CGRect) you should display the banner now.
        // adBanner.displayAd(viewController.getView(), viewController);
    }

    @Override
    public void didFail(FlurryAdBanner bannerAd, FlurryAdError adError, NSError errorDescription) {
        // Ideal time to fetch a new ad.
        adBanner.fetchAd(getView().getFrame());
    }
});

To be able to display an ad later, you have to fetch an ad first. Do this as early as possible.

// You can either only fetch the ad and display at a later time;
adBanner.fetchAd(viewController.getView().getFrame());
// Or you fetch and display the ad ASAP.
adBanner.fetchAndDisplayAd(viewController.getView(), viewController);

You have to pass a UIView and UIViewController when presenting the ad. Ideally you should setup the banner in a view controller subclass and specify this.getView() and this.
If you're developing a libGDX game you can just get the root view controller of the application:

UIViewController viewController = UIApplication.getSharedApplication().getKeyWindow().getRootViewController();

Try it out!

Add the code for interstitials and banners to your app. If you want to see test ads, you can specify special targeting options on your ad instance:

FlurryAdTargeting targeting = new FlurryAdTargeting();
targeting.setTestAdsEnabled(true);

ad.setTargeting(targeting);

Run the app and display the ads. With test ads enabled you should always see an ad.

Having trouble?
  • Make sure you have setup the Flurry SDK: Link
  • Make sure you have setup your app in your Flurry dashboard: Link
  • Check your logs for any errors, like network failures.
Next steps
  • Now that you have setup Flurry ads, why not log some events for analytics? Link
  • Take a look at our sample app: Link
  • Read the official Flurry documentation: Link