C/C++ Guides

Home

The Advertising Library and API

The MoSync Advertising C++ Library and Advertising C API make it easy for C/C++ programmer's to create advertisements and display them in mobile applications. You can get and set properties to determine if the advertisement should be visible in a certain context.

For a list of the platforms supported by the MoSync Advertising Library and API see our Feature/Platform Support page.

Example application

We make use of the NativeUI layouts to display advertisements. That means that the advertisment matches the look and feel of the target platform.

Here is a typical advertisement, in this case a banner ad, which we have implemented in the example application NativeUIDemo:

Take a look at the code of that example to see how we have implemented the advertisment feature.

Getting a publisher ID

To create a new banner on Android and test it during development, a publisher ID is required. You can get it by registering with Google AdMob.

For iOS no ID is required during development. When you add your application to the App Market you will need to provide information during the registration process.

The MoSync C++ Advertising Library

At the C++ level we have created a simple library contains two classes:

  • Banner — Provides a widget that displays advertisement to the user. When the user taps a banner, it triggers an action programmed into the advertisement. Your application is notified when an action starts or stops. This class requires our NativeUI Library; it can only be added to a NativeUI layout object.
  • BannerListener —  Provides methods for handling any changes in a Banner object. The class’s methods are called when a new advertisement is loaded, when a user interacts with an advertisement, and when errors occur.

The Advertising Library really makes developer’s life really easy: only three lines of code are needed to get a banner working inside your application:

Banner* banner = new Banner("yourPublisherID");
banner->requestContent(true);
aLayout->addBanner(banner);

In this example, on both iOS and Android, the advertisement will be created at the default banner size of 320 * 50 pixels. On Android you can specify other sizes for the advertisement in the constructor, including rectangular banner, IAB full banner and leaderboard sizes.

For full details of the Advertising Library classes and methods, see the MoSync API Reference.

The MoSync C Advertising API

The Advertising Library makes use of the set of C functions in the Advertising API:

  • maAdsBannerCreate — Creates a new banner. (Publisher ID required for Android.)
  • maAdsBannerDestroy — Destroy a banner.
  • maAdsAddBannerToLayout — Add a banner to a layout widget (requires the MoSync NativeUI).
  • maAdsRemoveBannerFromLayout — Remove a banner from a layout widget.
  • maAdsBannerSetProperty — Set a banner property value.
  • maAdsBannerGetProperty — Get a banner property value.

Ad banner properties that can be got/set include:

  • MA_ADS_HEIGHT — Get height.
  • MA_ADS_WIDTH — Get width.
  • MA_ADS_VISIBLE — Set/get visible status. Layouts will ignore invisible banners.
  • MA_ADS_ENABLED — Set/get enables status.
  • MA_ADS_TEST_DEVICE — Set device to recieve test ads.
  • MA_ADS_REQUEST_CONTENT — Set request status.
  • MA_ADS_IS READY — Returns true if the ad is sucessfully loaded and ready to display.

For full details of the Advertising API functions and properties, see the MoSync API Reference.

 

MoSync SDK 3.3
Copyright © 2013 MoSync AB
www.mosync.com