Adx3
EN
EN
  • Introduction to Broearn Ads Operation
    • Introduction to Broearn Ads Operation(SSP)
      • Login Operation
      • Website
      • Apps-For Android
      • Withdraw
      • Advertising Statistics
      • User Center
    • Introduction to Broearn Ads Operation (DSP)
      • Login Operation
      • Top-up
      • Ad Campaign Management
      • Ad Management
      • Advertising Statistics and Data Analysis
      • User Center
    • Adx3-Agent system manual(AGENT)
      • Log In
      • Add Account
      • Capital Account
      • Data Review
  • interface documentation
    • Monitor incident escalation(DSP)
    • Monitor incident escalation(SSP)
    • CPA, CPS Event Report
    • ANDRIOD
      • Start
        • Getting Started Guide
        • Test
      • Ad formats
        • Banner
        • Interstitial
        • Rewarded
        • APP Open
        • Native
        • Multiple
    • IOS
      • Get started
        • Getting Started Guide
        • Test
      • Ad formats
        • App Open
        • Interstital
        • Banner
        • Rewarded
        • Native
        • Multiple
  • FAQ
    • FAQ
Powered by GitBook
On this page
  • Prerequisites
  • Always test with test ads
  • Implementation
  • Load an ad
  • Create a Adx3NativeAdView
  • Register for callbacks
  • Display your ad
  1. interface documentation
  2. IOS
  3. Ad formats

Native

PreviousRewardedNextMultiple

Last updated 1 year ago

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 a native 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. This differs from other ad formats, which don't allow you to customize the appearance of the ad.

This guide will show you how to use the Adx3 Ads SDK to implement native ads in an iOS app.

Prerequisites

  • Complete the

Always test with test ads

When building and testing your apps, make sure you use test ads rather than live, production ads. Failure to do so can lead to the suspension of your account. The easiest way to load test ads is to use our dedicated test ad unit ID for all native advanced ads on iOS:

63a5739a75da4

It's been specially configured to return test ads for every request, and you're free to use it in your own apps while coding, testing, and debugging. Just make sure you replace it with your own ad unit ID before publishing your app.

Implementation

  • Load an ad

  • Create an Adx3NativeAdView

  • Register for callbacks

  • Display the ad

Load an ad

Native ads are loaded via Adx3NativeAd objects, Which send messages to their delegates according to the Adx3NativeAdViewDelegate protocol.

The following code demonstrates how to initialize an Adx3NativeAd:

import UIKit

class ViewController: UIViewController {
    
    let nativeAd = Adx3NativeAd()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
    }
    
    func loadNativeAd() {
        nativeAd.load(withPlacementID: "Your Placement ID", userId: "", delegate: self)
    }

}
#import "Adx3Framework/Adx3Ad.h"

@interface ViewController ()

@property (strong, nonatomic) Adx3NativeAd *nativeAd;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self loadNativeAd];
}

- (void)loadNativeAd {
    self.nativeAd = [[Adx3NativeAd alloc] init];
    [self.nativeAd loadNativeAdWithPlacementID:@"Your Placement ID" userId:@"" delegate:self];
} 

@end

Create a Adx3NativeAdView

Before you can create Adx3NativeAdView, you need to create a Xib file, Inherited from Adx3NativeAdView. The following code demonstrates how to create an Adx3NativeAdView:

func addNativeAdView() {
    nativeAdView = Bundle.main.loadNibNamed("Adx3NativeView", owner: nil, options: nil)?.first as? Adx3NativeAdView
    nativeAdView.translatesAutoresizingMaskIntoConstraints = false
    backgroundView.addSubview(nativeAdView)
    backgroundView.addConstraint(NSLayoutConstraint.init(item: nativeAdView!, attribute: .left, relatedBy: .equal, toItem: backgroundView, attribute: .left, multiplier: 1.0, constant: 0))
    backgroundView.addConstraint(NSLayoutConstraint.init(item: nativeAdView!, attribute: .right, relatedBy: .equal, toItem: backgroundView, attribute: .right, multiplier: 1.0, constant: 0))
    backgroundView.addConstraint(NSLayoutConstraint.init(item: nativeAdView!, attribute: .top, relatedBy: .equal, toItem: backgroundView, attribute: .top, multiplier: 1.0, constant: 0))
    backgroundView.addConstraint(NSLayoutConstraint.init(item: nativeAdView!, attribute: .bottom, relatedBy: .equal, toItem: backgroundView, attribute: .bottom, multiplier: 1.0, constant: 0))
}
- (void)addNativeAdView {
    [self.nativeAdView removeFromSuperview];
    self.nativeAdView = [[NSBundle mainBundle] loadNibNamed:@"Your Xib File Name" owner:nil options:nil]
        .firstObject;
    [self.nativeAdView setTranslatesAutoresizingMaskIntoConstraints:NO];

    NSDictionary *viewDictionary = NSDictionaryOfVariableBindings(_nativeAdView);
    [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[_nativeAdVi                                            options:0
                                                                      metrics:nil
                                                                        views:viewDictionary]];
    [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[_nativeAdView]|"
                                                                      options:0
                                                                      metrics:nil
                                                                        views:viewDictionary]];
} 

Register for callbacks

You should rely on the Adx3RewardDelegate (optional) to handle display events and request events. The following code shows how to implement the protocol:

extension ViewController {    
    func nativeAdDidReceive(_ nativeAd: Adx3NativeAd) {
        nativeAdView.nativeAd = nativeAd;
        nativeAdView.titleLabel!.text = nativeAd.title;
        nativeAdView.subLabel!.text = nativeAd.shop_name;
        nativeAdView.mediaView!.urlString = nativeAd.material;
        nativeAdView.descLabel!.text = nativeAd.describe;
        
        let queue = DispatchQueue.global()
        queue.async { [self] in
            let data = try! Data.init(contentsOf: URL(string: nativeAd.logo)!)
            let image = UIImage(data: data)
            nativeAdView.iconImageView!.image = image
        }
    }
    
    func nativeAdDidClick(withPlacementID placementID: String, extra: [AnyHashable : Any]) {
        
    }
    
    func nativeAdDidFailToReceiveAdWithError(_ error: Error) {
        
    }
}
- (void)nativeAdDidFailToReceiveAdWithError:(NSError *)error {
    NSLog(@"----%@----",error);
}

- (void)nativeAdDidReceiveNativeAd:(Adx3NativeAd *)nativeAd {
    NSLog(@"----Native AD Load Success----");
    self.nativeAdView.nativeAd = nativeAd;
    self.nativeAdView.titleLabel.text = nativeAd.title;
    self.nativeAdView.subLabel.text = nativeAd.shop_name;
    self.nativeAdView.mediaView.urlString = nativeAd.material;
    self.nativeAdView.descLabel.text = nativeAd.describe;
    
    dispatch_queue_t queue = dispatch_queue_create(0, 0);
    dispatch_async(queue, ^{
        NSData *data=[NSData dataWithContentsOfURL:[NSURL URLWithString:nativeAd.logo]];
        UIImage *img=[UIImage imageWithData:data];
        dispatch_async(dispatch_get_main_queue(), ^{
            self.nativeAdView.iconImageView.image = img;
        });
    });
}

- (void)nativeAdDidClickWithPlacementID:(NSString  *)placementID extra:(NSDictionary *)extra {
    NSLog(@"----")
}

Display your ad

Once you have loaded an ad, all that remains is to display it to your users.

Getting Started Guide