iOS Banner Ad

Banner ads provide a great way to add an additional revenue stream with minimal impact to the flow and usage of your app.

The MobileFuse SDK also supports delivery of expandable rich-media banner ads by default, which are more interactive and engaging than standard banner placements.

Prerequisites

Follow the initial integration guide:
Ensure that you have a Banner Ad Placement ID to use.

Display a banner ad in your app

The MFBannerAd class allows you to create and render banner ads within your app.

Note: Valid banner ad sizes are:

  • MOBILEFUSE_BANNER_SIZE_320x50

  • MOBILEFUSE_BANNER_SIZE_300x50

  • MOBILEFUSE_BANNER_SIZE_300x250

  • MOBILEFUSE_BANNER_SIZE_728x90

Your banner ad instance will render itself as a child of the view that you pass in to the loadAd method.

To create the banner ad, first allocate and initialize it with the size and placement ID that you’d like to use. Then set any position/constraints that you’d like to use, and finally call loadAd, the following sample code demonstrates this process:

ViewController.m

MFBannerAd *bannerAd; - (void)loadBanner { bannerAd = [[MFBannerAd alloc] initWithPlacementId:@"000000" withSize:MOBILEFUSE_BANNER_SIZE_320x50]; [bannerAd setPosition:CGPointMake(0, 0)]; [bannerAd registerAdCallbackReceiver:self]; [bannerAd loadAd:self.view]; }

Note: Ensure that you adjust the user interface of your app to account for the positioning of the banner. You should leave a margin between the displayed banner ad and your app UI to avoid potential mis-clicks on the ad creative.

Listening for event callbacks

Optionally, you can implement IMFAdCallbackReceiver to receive events from the banner ad instance. Pass the implementation to the registerAdCallbackReceiver method to start receiving callbacks:

[bannerAd registerAdCallbackReceiver:self]; - (void)onAdLoaded:(MFAd *)ad { // The ad has loaded - you are able to show the ad once this callback has triggered } - (void)onAdNotFilled:(MFAd *)ad { // There is no ad currently available to show to this user } - (void)onAdClosed:(MFAd *)ad { // The ad has been displayed and then closed } - (void)onAdRendered:(MFAd *)ad { // Triggered when the ad is first shown to the user } - (void)onAdExpanded:(MFAd *)ad { // The ad has been expanded into full screen - will only be triggered for expandable banner ads } - (void)onAdCollapsed:(MFAd *)ad { // The ad has been collapsed back down into standard banner size } - (void)onAdClicked:(MFAd *)ad { // The user has clicked the ad } - (void)onAdExpired:(MFAd *)ad { // The ad has expired before being displayed - you should manually try to load a new ad here } - (void)onAdError:(MFAd *)ad withMessage:(NSString *)message { // An error occured - the message argument will contain details of what went wrong }

Destroying an ad

Call the destroy method to remove and deallocate the banner ad’s resources:

[bannerAd destroy];

Advanced: Configure Ad Rotation

Banner ads can be set to rotate on a pre-set time interval. This is useful to increase the number of banner impressions that will be shown to your users. By default banner ad rotation is disabled. The minimum refresh period is 30 seconds - you cannot set the banner to auto refresh more frequently than once every 30 seconds.

Example: Configure ad to refresh every 60 seconds:

Example: Manually handle refreshing of the ad, for example you may want to fetch a new ad when a view is changed within your app: