Native Ads | iOS

With Native Ads, publishers need to supply different UI components to the SDK to perform the final rendering of an Ad. However, Smaato recommends that all UI components be added to a dedicated UIView container to handle the clicks by the SDK. Only when the container is registered with the SDK will an Ad be visible with clicks be enabled and beacons called.

// Step 1: Declare a property in the view controller header:
@property SOMANativeAd* nativeAd;
// Step 2: Instantiate:
self.nativeAd = [[SOMANativeAd alloc] initWithPublisherId:@"0" adSpaceId:@"0"];
self.nativeAd.delegate = self;
  
// Step 3: Configure UI components
self.nativeAd.labelForTitle = self.title; // an UILable instance to render the title
self.nativeAd.labelForDescription = self.text; // an UILable instance to render the description
self.nativeAd.imageViewForIcon = self.icon; // an UIImageView instance to render the icon
self.nativeAd.imageViewForMainImage = self.photo; // an UIImageView instance to render the big image
 
// Step 4: Load the ad
[self.nativeAd load];
  
// Stop 5: Once the ad is loaded, make the final configuration and then register the container
- (void)somaNativeAdDidLoad:(SOMANativeAd*)nativeAd{
    self.callToAction.text = nativeAd.callToAction; // UILable instance for the "call-to-action" e.g. Install, Visit etc.
    [self updateRating:nativeAd.rating]; // Optional: native ad comes with a floating point rating e.g. 4.5. Typically shown in stars.
 
 
    // Finally, register the container. Make sure all the native ad UI components are children to this container view.
    [nativeAd registerViewForUserInteraction:self.container];
 
}
// thats it!

Native Ad Templates

From SOMA iOS SDK version 8.0.4 on, you can use native ad templates geared for the most popular and common in-app uses:

  • Content wall
  • Content stream
  • Newsfeed
  • App wall
  • Chat list
  • Carousel

Integrating a layout now needs even less coding than before. Here is a step-by-step guide to adding a ‘News Feed’ layout to a native ad:

Step 1: Instantiate a native ad and set the delegate as always:

self.nativeAd = [[SOMANativeAd alloc] initWithPublisherId:@"0" adSpaceId:@"3075"]; // PUT your information
self.nativeAd.delegate = self;

Step 2: Set the desired layout and load.

self.nativeAd.layout = SOMANativeAdLayoutNewsFeed; //Example; refer to minimum height values list below for all options
self.[nativeAd load];

Step 3: Register the native ad container view for user interaction once the ad is loaded. Edit the delegate method as below:

- (void)somaNativeAdDidLoad:(SOMANativeAd*)nativeAd{
[self.nativeAd registerViewForUserInteraction:self.nativeAdContainerView];
}

Review the layout and adjust its height accordingly to render correctly if necessary; minimum height values typically required are:

  • SOMANativeAdLayoutCarousel: 280
  • SOMANativeAdLayoutAppWall: 50
  • SOMANativeAdLayoutNewsFeed : 50
  • SOMANativeAdLayoutChatList: 50
  • SOMANativeAdLayoutContentWall:300
  • SOMANativeAdLayoutContentStream: 250

 

MoPub Adplacer Integration

When using MoPub’s Adplacer feature, a native ad renderer needs to be set up. This set up needs to contain an additional reference to our Mediation event so that Smaato native ad responses can be placed in collections:

  MPStaticNativeAdRendererSettings *nativeAdSettings = [[MPStaticNativeAdRendererSettings alloc] init];
    nativeAdSettings.renderingViewClass = [MoPubNativeAdCell class];
    nativeAdSettings.viewSizeHandler = ^(CGFloat maximumWidth) {
        return CGSizeMake(maximumWidth, 312.0f);
    };
    
    MPNativeAdRendererConfiguration *config = [MPStaticNativeAdRenderer rendererConfigurationWithRendererSettings:nativeAdSettings];

    // ==== REQUIRED: Add support for Smaato custom event ====
    config.supportedCustomEvents = @[@"SOMAMoPubNativeCustomEvent"];
    // ==== REQUIRED: Add support for Smaato custom event ====
    self.adPlacer = [MPTableViewAdPlacer placerWithTableView:self.tableView viewController:self rendererConfigurations:@[config]];

This setup allows placing and loading the ads into both UITableView and UICollectionView.

Modified: August 30, 2019 at 2:47 pm