Skip to content

Implementation Guide: iOS SDK

Manny edited this page Oct 6, 2013 · 12 revisions

This tutorial requires an activated AdFlake.com account as well as a minimum familiarity with ObjectiveC, iOS development and Xcode project configuration.

The following five steps will enable your application to utilize AdFlake's awesome features.

1. AdFlake

On iOS we're providing the source code rather than a precompiled library. Simply drag the AdFlake-SDK folder into your Xcode project. Before you compile your project a modification of the file AdFlakeConfiguration.h is necessary. Simply enable the defines of the ad networks you want to enable. To enable Google AdMob, open the AdFlakeConfiguration.h and change the line:

 //#define AdFlake_Enable_SDK_GoogleAdMob

to

 #define AdFlake_Enable_SDK_GoogleAdMob

We are currently in contact with our supported ad networks to determine if we can package the ad network SDKs in a future release.

The AdFlake SDK does not use Automatic Reference Counting, so if you're using ARC it has to be disabled.

2. TouchJSON

We're using TouchJSON for JSON parsing. If you're already using TouchJSON in your project you can skip this step. To successfully build drag the TouchJSON redistribution folder bundled with the AdFlake SDK into your Xcode project.

3. System Frameworks

Most ad network SDKs require additional system frameworks. Add the following system frameworks which are required by most of the ad network SDK's:

  • AddressBook
  • AudioToolbox
  • AVFoundation
  • CoreLocation
  • libsqlite3
  • libz
  • MapKit
  • AdSupport

The following additional frameworks are required by the iAd adapter:

  • iAd
  • QuartzCore
  • SystemConfiguration

For distribution on older iOS versions some of the system frameworks have to be weak linked. It is possible that additional system frameworks have to be added, if your project does not build, consult the ad network's implementation guide line.

4. Ad Networks

If no specific ad network adapter is enabled (by modifying the AdFlakeConfiguration.h file) your app will only display AdFlake House Ads and Apple iAds.

Registering with an ad network and including their SDK into your project together with the AdFlake SDK enable the app to show the specified networks ads.

Don't forget to configure your ad networks on AdFlake.com and set the network traffic allocation for the specified ad providers through the AdFlake ad network settings and you are good to go.

5. AdFlakeView

Finally, to display the mediated ads simply implement AdFlakeDelegate’s two requirements, request an AdFlakeView and add it your view hierarchy. Add the following code to the view controller class where you want to display ads in. Make sure to implement the AdFlakeDelegate protocol in your view controller class.

#import "AdFlakeView.h"

- (void)viewDidLoad {
     [super viewDidLoad];
      AdFlakeView *adView = [AdFlakeView requestAdFlakeViewWithDelegate:self];
      adView.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleRightMargin;
     [self.view addSubview:adView];
}

- (NSString *)adFlakeApplicationKey {
     return YOUR_AD_FLAKE_APPLICATION_SDK_KEY;
 }

- (UIViewController *)viewControllerForPresentingModalView {
     return [UIApplication sharedApplication].keyWindow.rootViewController;
}

6. Optional Implementation

Ad Sizes

Ads from different ad networks can have different sizes for example AdMob’s banner is 320x48 while Millennial Media’s is 320x53.

AdFlakeView’s default banner size is 320x50 and by design any trimming or expansion to precisely fit [AdFlakeView actualAdSize] is up to the app.

- (void)adFlakeDidReceiveAd:(AdFlakeView *)adFlakeView { 
     CGSize adSize = [adView actualAdSize];
     CGRect newFrame = adView.frame;
     newFrame.size = adSize;
     newFrame.origin.x = (self.view.bounds.size.width - adSize.width)/ 2;
     adView.frame = newFrame;
}

Device Orientation

Some ad networks including iAd will vary their ad dimensions with device orientation. If your app supports rotation you must forward orientation changes to AdFlakeView by invoking AdFlakeView.rotateToOrientation: within your UIViewController’s should/willAutorotateToInterfaceOrientation: implementation and then refit as per 6.1. If your app’s notion of orientation somehow differs from UIDevice.orientation you must also implement AdFlakeDelegate.adFlakeCurrentOrientation to return the appropriate value.