Native ads are ad assets that are presented to users via UI components that are native to the platform. They're shown using the same classes you already use in your storyboards, and can be formatted to match your app's visual design. When an ad loads, your app receives an ad object that contains its assets, and the app (rather than the SDK) is then responsible for displaying them.
The guide will show you how to use the Orion Ads SDK to implement native ads in an iOS application, as well as some important things to consider along the way.
Loading Ads
Native ads are loaded via CMANativeAdLoader objects, which send messages to their delegates according to the CMANativeAdLoaderDelegate protocol.
Initialize the ad loader
Before you can load an ad, you have to initialize the ad loader. The following code demonstrates how to initialize a CMANativeAdLoader
Once your CMANativeAdLoader is initialized, call its loadAd: method to request an ad.
[self.adLoader loadAd]
When to request ads
Apps displaying native ads are free to request them in advance of when they'll actually be displayed. In many cases, this is the recommended practice. An app displaying a list of items with native ads mixed in, for example, can load native ads for the whole list, knowing that some will be shown only after the user scrolls the view and some may not be displayed at all.
Determining when loading has finished
After an app calls loadAd:, it can get the results of the request via calls to:
- (void)nativeAdLoaderLoaded:(CMANativeAdLoader *)nativeAdLoader;
{
NSLog(@"Ad was loaded.");
// Get Ad Object.
self.nativeAd = [nativeAdLoader nextNativeAd];
// Register Relateds Ad Events.
[self.nativeAd registerViewForInteraction:self.adContentView withViewController:self];
// Next, you might need to attach ad object to your custom view.
}
- (void)nativeAdLoader:(CMANativeAdLoader *)nativeAdLoader
didFailToReceiveAdWithError:(CMARequestError *)error;
{
NSLog([NSString stringWithFormat:@"NG> Ad failed to load. %@", error]);
}