Skip to content

Instantly share code, notes, and snippets.

@anbykov
Last active December 16, 2015 16:10
Show Gist options
  • Save anbykov/5461548 to your computer and use it in GitHub Desktop.
Save anbykov/5461548 to your computer and use it in GitHub Desktop.
Publisher SDK Integration Guide iOS

Publisher SDK Integration Guide iOS

Contents

Introduction

This document describes how to integrate the RadiumOne publisher SDK for iOS into your application.

Objective of this document

This document describes how to:

  • Add the Mobclix SDK files to your project
  • Integrate with Interface Builder
  • Integrate without Interface Builder
  • Integrate Your Code and set up App Delegate

Getting Started

Before you start, you should have the following files:

RadiumOneSDKContains the RadiumOne SDK for iOS
DemoApplicationFully functional iOS application that integrates all features of the RadiumOne SDK.
documentationSDK integration guide to help new developers integrate the RadiumOne SDK for iOS into their applications. This is the document that you are now reading.

How to Add the RadiumOne SDK files to your Project

  1. Open up your iOS project in xCode.
  2. Select File -> Add Files to “[your project]”
  3. Select Folder with SDK library and headers in dialog
  4. When the dialog box appears, check the Copy Items into destination group’s folder checkbox.

How to Add the RadiumOne SDK files to your project

Linking to the Dependency Frameworks

To correct linking you must add few required frameworks:

Linking to the Dependency Framework

Integrating with Your Code

Setting up your App Delegate

You will need to initialize RadiumOne SDK in your App Delegate.

Setting up your App Delegate

  1. At the top of this file you should add #import "RadiumOneAd.h"
  2. You should find applicationDidFinishLaunching: method, or application:didFinishLaunchingWithOptions: method and insert [RadiumOneAd startWithApplicationId:@"your-application-id"];
    #import "RadiumOneAppDelegate.h"
    #import "RadiumOneRootViewController.h"
    
    #import "RadiumOneAd.h"
    
    @implementation RadiumOneAppDelegate
    - (BOOL)application:(UIApplication *)application
    didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
        [RadiumOneAd startWithApplicationId:@"your-application-id"];
    
        // Your initialization code here
        return YES;
    
    }
    
    // Other methods
    
    @end

Integrating with Interface Builder

  1. Set up your Interface file ([Your view controller].h) with “adView” as an outlet:
    #import <UIKit/UIKit.h>
    #import "RadiumOneAdView.h"

    @interface YourViewController : UIViewController
    {
        RadiumOneAdView *adView;
    }

    @property (nonatomic, retain) IBOutlet RadiumOneAdView *adView;

    @end
  1. Set up your Implementation file ([Your view controller].m):
    @implementation YourViewController
    @synthesize adView;
  1. Set up your Interface Builder file ([Your view controller].xib):

3.1. Add new view into main view

3.2. Set up class for this view (RadiumOne320x50AdView for 320x50 banner, RadiumOne300x250AdView for 300x250 banner and RadiumOne728x90AdView for iPad 728x90 banner):

Set up class for the View

3.3. Set up ad view size and layout:

Set ad view size

3.4. Connect this view with adView object:

Connect view with adView object

3.5. Go to the section “Working with Ads” in this document.

Integrating without Interface Builder

  1. Set up your Interface file ([Your view controller].h) with “adView” as an outlet:
    #import <UIKit/UIKit.h>
    #import "RadiumOneAdView.h"

    @interface YourViewController : UIViewController
    {
        RadiumOneAdView *adView;
    }
    @property (nonatomic, retain) RadiumOneAdView *adView;
    @end
  1. Set up your Implementation file ([Your view controller].m):
    #import "YourViewController.h"

    @implementation YourViewController
    @synthesize adView;

    - (void) viewDidLoad
    {
        [super viewDidLoad];
        self.adView = [[[RadiumOne320x50AdView alloc]
    initWithFrame:CGRectMake(0, 0, 320, 250)] autorelease];
        [self.view addSubview:self.adView];
    }

    @end
  1. Go to the section “Working with Ads” in this document.

Working with Ads

Pause  ad  requests  when  your  view  disappears

In your view controller’s viewDidDisappear method, you should stop the ad refreshing timer by calling pauseAdAutoRefresh. If you don’t make this all view controllers with banners will always update content.

    - (void) viewDidDisappear:(BOOL)animated
    {
        [super viewDidDisappear:animated];
        [self.adView pauseAdAutoRefresh];
    }

Resume  ad  requests  when  your  view  appears

In your view controller’s viewWillAppear method, you should start the ad refresh timer by calling resumeAdAutoRefresh.

    - (void) viewWillAppear:(BOOL)animated
    {
        [super viewWillAppear:animated];
        [self.adView resumeAdAutoRefresh];
    }

Canceling and releasing ad view

    - (void) dealloc
    {
        [self.adView cancelAd];
        self.adView = nil;
        [super dealloc];
    }
    - (void) viewDidUnload
    {
        [self.adView cancelAd];
        [self.adView removeFromSuperview];
        self.adView = nil;
        [super viewDidUnload];
    }

Receive information from Ad View

If you want receive information about Ads loading or errors you can use optional delegate.

    - (void) viewDidLoad
    {
        // Your code and adView initialization
        self.adView.delegate = (id)self;
    }

Now you can add optional delegate methods into your code:

    - (void) adViewDidFinishLoad:(RadiumOneAdView*)adView
    {
        // Ad view loads the banner
    }

    - (void) adView:(RadiumOneAdView*)adView
    didFailLoadWithError:(NSError*)error
    {
        UIAlertView *alertView = [[UIAlertView alloc]
    initWithTitle:@"Error" message:[error localizedDescription]
    delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];

        [alertView show];
        [alertView release];
    }

The method adViewDidFinishLoad: called after adView loaded the banner.

The methods adView:didFailLoadWithError: called when something bad happened:

  • adView can not receive information from server
  • adView received information but can not parse it
  • adView received information without supported banners

Integrating Full Screen Ads

  1. Set up your Interface file ([Your view controller].h) with “fullScreenAdViewController”:
    #import <UIKit/UIKit.h>
    #import "RadiumOneFullScreenAdViewController.h"

    @interface YourViewController : UIViewController <
    RadiumOneFullScreenAdViewControllerDelegate >
    {
        RadiumOneFullScreenAdViewController *fullScreenViewController;
    }

    @property (nonatomic, retain) RadiumOneFullScreenAdViewController
    *fullScreenViewController;

    @end
  1. Set up your Implementation file ([Your view controller].m):
    #import "YourViewController.h"

    @implementation YourViewController
    @synthesize fullScreenViewController;
    - (void) dealloc
    {
        self.fullScreenViewController = nil;

        [super dealloc];
    }

    @end
  1. Now you can use it in 2 different cases.

Requesting Ads and Manually Displaying

In this case RadiumOneFullScreenAdViewController not opened automatically after content will be loaded.

    - (void) startAdPreloading
    {
        self.fullScreenViewController =
    [[[RadiumOneFullScreenAdViewController alloc] init] autorelease];
        self.fullScreenViewController.delegate = self;
        [self.fullScreenViewController requestAd];
    }

    // Start only after fullScreenAdViewControllerDidFinishLoad: methods was called
    - (void) showAd
    {
        [self.fullScreenViewController
        displayRequestedAdFromViewController:self];
    }

    - (void)
    fullScreenAdViewControllerDidFinishLoad:(RadiumOneFullScreenAdViewController*) fullScreenAdViewController
    {
    // The Ad preloaded
    }

    - (void)
    fullScreenAdViewController:(RadiumOneFullScreenAdViewController*)
    fullScreenAdViewController didFailToLoadWithError:(NSError*) error
    {
        UIAlertView *alertView = [[UIAlertView alloc]
    initWithTitle:@"Error" message:[error localizedDescription]
    delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [alertView show];
        [alertView release];
        self.fullScreenViewController = nil;
    }

    - (void)
    fullScreenAdViewControllerDidDismiss:(RadiumOneFullScreenAdViewController*) fullScreenAdViewController
    {
        self.fullScreenViewController = nil;
    }

Requesting Ads and Automatically Displaying

In this case RadiumOneFullScreenAdViewController opened automatically after content will be loaded.

    - (void) preloadAndOpenAd
    {
        self.fullScreenViewController =
    [[[RadiumOneFullScreenAdViewController alloc] init] autorelease];
        self.fullScreenViewController.delegate = self;
        [self.fullScreenViewController
    requestAndDisplayAdFromViewController:self];
    }

    - (void)
    fullScreenAdViewController:(RadiumOneFullScreenAdViewController*)
    fullScreenAdViewController didFailToLoadWithError:(NSError*) error
    {
        UIAlertView *alertView = [[UIAlertView alloc]
    initWithTitle:@"Error" message:[error localizedDescription]
    delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [alertView show];
        [alertView release];
        self.fullScreenViewController = nil;
    }

    - (void)
    fullScreenAdViewControllerDidDismiss:(RadiumOneFullScreenAdViewController*) fullScreenAdViewController
    {
        self.fullScreenViewController = nil;
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment