Native Ads Integration For iOS english - Hiroaki-Shinoda/Geniee-iOS-SDK GitHub Wiki

Native Ads Integration For iOS

Native Ads are a component-based ad format that allow publisher to display the customized ads on the application, how layouts headlines and call to action button. By choosing colors, image size and fonts etc for your application, you are able to display natural, well matched advertisement that can give better user experience. Ad impressions, ad clicks tracking, processing Advertising SDK.

Preparation

To Implement the Native ads, you need to install the Geniee SDK to the project. Please follow the Start Guide for the process. Start Guide

Class and Protocol

Class for iOS Native Ad;

  • GNNativeAdRequest : Class to Request Native Ad with asynchronous
  • GNNativeAd : Class to provide information of Native Ad
  • GNNativeAdRequestDelegate : Protocol to receive loading event of Native Ad

Set up Native Ad

  1. Add GNAdSDK.framework to your project. Start Guide

  2. Import GNNativeAdRequest.h, GNNativeAd.h

    #import <GNAdSDK/GNNativeAdRequest.h>
    #import <GNAdSDK/GNNativeAd.h>
    
  3. Use GNNativeAdRequestDelegate Protocol

    @interface TableViewController () <GNNativeAdRequestDelegate>
    {
    }
    
  4. Declare GNNativeAdRequest variable

    GNNativeAdRequest *_nativeAdRequest;
    
  5. Initialise GNNativeAdRequest instance

    _nativeAdRequest = [[GNNativeAdRequest alloc] initWithID:@"YOUR_SSP_APP_ID"];
    
  6. Set up GNNativeAdRequest delegate Notice result of native ad loading event through the delegate. Set the instance of GNNativeAdRequestDelegate to this delegate.

    _nativeAdRequest.delegate = self;
    
  7. Load Native Ad

    [_nativeAdRequest loadAds];
    
  8. Implement GNNativeAdRequestDelegate Protocol
    Implement CallBack function of GNNativeAdRequestDelegate to receive the result of native ad loading event.

    - (void)nativeAdRequestDidReceiveAds:(NSArray*)nativeAds;
    - (void)nativeAdRequest:(GNNativeAdRequest *)request didFailToReceiveAdsWithError:(NSError *)error;
    

Received native ads is return by an array of GNNativeAd arguments.
You can use the zoneID field of GNNativeAd to determine which ad has been received.
The number of elements in the array GNNativeAd :
- one : Select one APP_ID when Initialize GNNativeAdRequest
- Multiple : Select Multiple APP_ID when Initialize GNNativeAdRequest

  1. Set up delegate to nil, when instance of GNNativeAdRequest is released.
    - (void)dealloc
    {
        _nativeAdRequest.delegate = nil;
    }
    
  • e.g Implementation of UITableViewController :
    #import <GNAdSDK/GNNativeAdRequest.h>
    #import <GNAdSDK/GNNativeAd.h>
    
    @interface TableViewController () <GNNativeAdRequestDelegate>
    {
        GNNativeAdRequest *_nativeAdRequest;
    }
    @property (nonatomic, strong) NSMutableArray *cellDataList;
    @end
    
    @implementation TableViewController
    
    - (void)viewDidLoad {
        [super viewDidLoad];
    
        _nativeAdRequest = [[GNNativeAdRequest alloc] initWithID:@"YOUR_SSP_APP_ID"];
        _nativeAdRequest.delegate = self;
        [_nativeAdRequest loadAds];
    }
    
    - (void)nativeAdRequestDidReceiveAds:(NSArray*)nativeAds
    {
        for (GNNativeAd *nativeAd in nativeAds) {
            // You can identify the GNNativeAd by using the zoneID field of GNNativeAd.
            //if ([nativeAd.zoneID isEqualToString:@"YOUR_SSP_APP_ID"]) {
            //    [_cellDataList addObject:nativeAd];
            //}
            [_cellDataList addObject:nativeAd];
        }
    }
    
    - (void)nativeAdRequest:(GNNativeAdRequest *)request didFailToReceiveAdsWithError:(NSError *)error
    {
        NSLog(@"TableViewController: didFailToReceiveAdsWithError : %@.", [error localizedDescription]);
    }
    

Get Ads in multiple AdZones at the same time

  • In order to get the multiple AdZones of advertising at the same time,
    you need to initialise the instance by specifying APPID of multiple AdZones.

  • It is possible to get maximum 10 Ads at the same time.

  • Separate multiple APP_ID by comma, Do not put SPACE between APP_ID.

    _nativeAdRequest = [[GNNativeAdRequest alloc] initWithID:@"APPID1,APPID2,APPID3,...,APPID10"];
    

Rendering Native Ad

You need to render Native Ad based on information of received data.

  • The type of information data refers GNNativeAd.h class

  • If the information data (NSString type) is not set , it will be nil

  • If the information data (int, double type) is not set , it will be 0

    Name Type Data
    zoneID NSString ID for AdZone in Geniee
    advertiser NSString Name of client
    title NSString Title of feed advertisement
    description NSString description of advertisment
    cta NSString text for "call to action"
    icon_aspectRatio double Aspect ratio of icon image
    icon_url NSString URL of icon image
    icon_height int heigh of icon
    icon_width int width of icon
    screenshots_aspectRatio double aspect ratio of screenshot
    screenshots_url NSString URL of screenshot image
    screenshots_height int heigh of screenshot image
    screenshots_width int width of screenshot image
    app_appName NSString Name of App
    app_appid NSString App ID(ios:number、Android:package)
    app_rating double Evaluation of App
    app_storeURL NSString URL of App store
    app_targetAge NSString Target age of App (e.g:ios App:rating)
  • e.g.:Implementation of UITableViewController : In the case the native ads information is set in dashboard :

    • title
    • description
    • icon image URL
    - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
    {
        return 1;
    }
    
    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
    {
        return _cellDataList.count;
    }
    
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        static NSString *CellIdentifier = @"SampleDataCell";
        TableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
    
        if ([_cellDataList objectAtIndex:indexPath.row] isKindOfClass:[GNNativeAd class](/Hiroaki-Shinoda/Geniee-iOS-SDK/wiki/_cellDataList-objectAtIndex:indexPath.row]-isKindOfClass:[GNNativeAd-class)) {
            GNNativeAd *nativeAd = (GNNativeAd *)[_cellDataList objectAtIndex:indexPath.row];
            if (nativeAd != nil) {
                cell.nativeAd = nativeAd;
                cell.title.text = nativeAd.title;
                cell.description.text = nativeAd.description;
                cell.icon.image = nil;
                NSURL *url = [NSURL URLWithString:nativeAd.icon_url];
                [TableViewController requestImageWithURL:url completion:^(UIImage *image, NSError *error) {
                    if (error) return;
                    cell.icon.image = image;
                }];
                [nativeAd trackingImpressionWithView:cell];
            }
        } else {
            // The other cell rendering (not GNNativeAd)
        }
        return cell;
    }
    
  • Image of UITableViewController

    image

Impression report for Native Ad

  • When the Native Ad is rendered, you can extract the ad impression report.

  • For impressions native ads that has been previously reported, can not be reported again.

  • You need to request Native Ad again to display new advertisement.

    [nativeAd trackingImpressionWithView:cell];
    

Click tracking for Native Ad

  • When the native ad is clicked, it will start the ad landing page in the external browser.

    [nativeAd trackingClick];
    
  • e.g.: implementation of UITableViewController

    -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
    {
        TableViewCell *cell = (TableViewCell*)[tableView cellForRowAtIndexPath:indexPath];
        if (cell.nativeAd != nil) {
            [cell.nativeAd trackingClick];
        } else {
            // The other cell rendering (not GNNativeAd)
        }
    }
    

Control of screen transition landing page

Landing page of ads starts on the external browser by default. It is possible to start in apps browser, when the callback function of GNNativeAdRequestDelegate is implemented And it is also possible to control the activation of an external browser by the returning function.

  • YES : It will start an external browser.

  • NO : It will not start the external browser.

    - (BOOL)shouldStartExternalBrowserWithClick:(GNNativeAd *)nativeAd landingURL:(NSString *)landingURL;
    

Re-acquisition Native Ad

  • It is necessary to re-acquisition native ads to display new advertisement.

    [_nativeAdRequest loadAds];
    
  • e.g.: UITableViewController

    - (void)scrollViewDidScroll:(UIScrollView *)scrollView
    {
        [_nativeAdRequest loadAds];
    }
    
  • It receive the result by callback of GNNativeAdRequestDelegate

    - (void)nativeAdRequestDidReceiveAds:(NSArray*)nativeAds;
    - (void)nativeAdRequest:(GNNativeAdRequest *)request didFailToReceiveAdsWithError:(NSError *)error;
    

Integration Ads SDK in Swift

It is necessary to write an import statement in header files to Objective-C bridging header file,
when it utilises iOS SDK (Objective-C) class from Swift.

  • Add <name of project>-Bridging-Header.h file to project.

  • Add import in <name of project>-Bridging-Header.h file.

    #import <GNAdSDK/GNNativeAdRequest.h>
    #import <GNAdSDK/GNNativeAd.h>
    
  • Set file name to [Build Settings] in project Choose the target and set the <name of Project>-Bridging-Header.h to [Build Settings]->[Swift Compiler]->[Code Generation]->[Objective-C bridging header] image