Video Ads Integration For iOS English - Hiroaki-Shinoda/Geniee-iOS-SDK GitHub Wiki

Implementation of Video Ads

VIDEO ads are displayed at natural transition points in the flow of an app like interstitial ads, such as start-up the application, or between activities or during the pause between levels in a game.

Preparation

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

Class and protocol

iOS video ad delivery use this following class.

  • GNAdVideo Asynchronous retrieve the video ads and the class for display
  • GNAdVideoDelegate Interstitial cycle event processing protocol

Set Up video ads

  1. Add GNAdSDK.framework to project. Start Guide

  2. Import GNAdVideo.h.

    #import <GNAdSDK/GNAdVideo.h>
  3. Apply GNAdVideoDelegate protocol.

    @interface MyViewController : UIViewController<GNAdVideoDelegate>
    {
    }
  4. Declare the variable of GNAdVideo.

    GNAdVideo *_videoAd;
  5. Initialise the instance of GNAdVideo.

    _videoAd = [[GNAdVideo alloc] initWithID:@"YOUR_SSP_APP_ID_FOR_VIDEO"];

YOUR_SSP_APP_ID sets management ID of AdsZone in Geniee.

  1. Set the delegate of GNAdVideo.
  • Video ad processing cycle events will be notified via delegate.
  • Set GNAdVideoDelegate the instance variable adopted protocol.
    _videoAd.delegate = self;
  1. Set the root ViewController of GNAdVideo.

    _videoAd.rootViewController = self;
  2. When you release the instance of GNAdVideo set the delegate to nil.

    - (void)dealloc
    {
        _videoAd.delegate = nil;
    }
  • Example Implementation of MyViewController:

    // MyViewController.h
    
    #import <GNAdSDK/GNAdVideo.h>
    
    @interface MyViewController : UIViewController<GNAdVideoDelegate>
    {
       GNAdVideo *_videoAd;
    }
    @end
    //  MyViewController.m
    
    @implementation MyViewController
    
    - (void)viewDidLoad {
        [super viewDidLoad];
    
        _videoAd = [[GNAdVideo alloc] initWithID:@"YOUR_SSP_APP_ID_FOR_VIDEO"];
        _videoAd.delegate = self;
        _videoAd.rootViewController = self;
    }
    
    - (void)dealloc
    {
        _videoAd.delegate = nil;
    }
    @end

Load Video Ads

Load video ads display for the tag from Ad server.
GNAdVideo is preloaded before display, please set the appropriate time to prepare for completion of ads.

  • If it successes to load, it will be notified by onGNAdVideoReceiveSetting callback function of delegate.

  • If it fails to load, it will be notified by onGNAdVideoFailedToReceiveSetting callback function of delegate.

    [_videoAd load];

Display Video Ads

Please check whether video ads is ready to be displayed before displaying period.

  • This example explains how to display video ads at the time of the screen transition.

    - (void)showEventFunc
    {
        if ([_videoAd isReady]) {
            [_videoAd show:self];
        }
    }
    • Parameterself:Variable of ViewController of the current screen

Update Video Ads

To update video ads, you need to display to re-load ads.

Set Alternative Interstitial Ads

  • When there is no stock or acquisition failure on the video ads, you can display alternative interstitial ads.

  • Set the alternative interstitial ads and set management ID of interstitial AdZone.

    [_videoAd setAlternativeInterstitialAppID:@"YOUR_SSP_APP_ID_FOR_INTERSTITIAL"];

GNAdVideoDelegate protocol

  • Implement CallBack function of GNAdVideoDelegate and you will receive advertisement processing cycle events.

    @protocol GNAdVideoDelegate <NSObject>
    
    @required
    
    /// It will be sent when the reading of advertising data has been completed.
    - (void)onGNAdVideoReceiveSetting;
    
    @optional
    
    /// It will be sent to when that failed to read Ad in the cause such as a network error.
    - (void)onGNAdVideoFailedToReceiveSetting;
    
    /// Video ad screen will be sent immediately after that is closed.
    - (void)onGNAdVideoClose;
    
    /// From the management screen, buttons were installed in advertising screen will be tapped.
    /// Alternate interstitial advertising screen will be sent immediately after that is closed.
    /// Number of buttons have been tapped, you will be notified by `nButtonIndex` parameters.
    - (void)onGNAdVideoButtonClick:(NSUInteger)nButtonIndex;
    
    @end

Using iOS SDK from Swift

You can use iOS SDK (Objective-C) class from the Swift, by writing the import statement of header files in a file called Objective-C bridging header.

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

  • Write Import-Sentence in <ProjectName>-Bridging-Header.h file.

    #import <GNAdSDK/GNAdVideo.h>
  • Set file name in the "Build Settings" in project.
    In settings, please select a target in the project root and set <ProjectName>-Bridging-Header.h to 「Build Settings」->「Swift Compiler - Code Generation」->「Objective-C bridging header」.
    image

⚠️ **GitHub.com Fallback** ⚠️