Put AdWhirl Ads into Your iPhone App

Monetizing an iPhone app comes in many flavors these days--you don't just need to charge for your app. Today I want to give you a step-by-step guide to getting ads into your application. You will be shocked how easy it is!

When I decided to release a lite ad-supported version of my app, I searched around to find out about ad providers. Luckily, in my search, I happened upon AdWhirl. AdWhirl is not actually an ad provider--instead, they provide an interface to other ad provider networks, allowing you to add one ad API into your app, and get 8 ad providers instantly (including the ability to put in your own ads).

AdWhirl has outstanding step-by-step instructions on their site here. I was trying to incorporate Quattro Wireless into my app and was having some issues, not the least of which was the lack of cut-and-paste of example code. I was searching on example code when I found AdWhirl, which includes Quattro Wireless as a provider. And AdWhirl made it easy for me to set up my ads, so it was a no brainer. [Update--I have received word from Quattro Wireless that they do provide cut and paste code in their developer wiki. My mistake--I guess I did not look in the right place.]

But now, let's look at some code. For my sliding tile game, I used the cocos2d framework. I was worried this would make it hard to incorporate in AdWhirl, but it was no problem at all! Take the steps in the instructions document above, then do a few simple steps to incorporate AdWhirl into your app:

First, I recommend adding a few constants into a common header file:

#define PUBLISHER_ID @"12345678901234567890"
#define SITE_ID @"MyApplication"
#define ADWHIRLAPPKEY @"1234567890abcdef1234567890"

These are the constants needed by the AdWhirl interface.

Include these variables in your scene header file:

ARRollerView *rollerView;
BOOL isPaused;

Next, I went into my main Scene file and put the following at the end of the init method:

rollerView = [ARRollerView requestRollerViewWithDelegate:self];
[ARRollerView startPreFetchingConfigurationDataWithDelegate:self];

rollerView.center = CGPointMake(160, 454);
UIView *myView = [[Director sharedDirector] openGLView];
[myView addSubview:rollerView];

isPaused = FALSE;

This code will begin prefetching data for ads. Also, you will notice I specifically placed the ads at the bottom of the view--that took some trial and error to get it to line up perfectly. isPaused is going to be the notifier to pause the game timer while an ad would be displayed if the user clicks on one during game play.

Now, your scene will need to provide a method to return your app key:

- (NSString*)adWhirlApplicationKey
return ADWHIRLAPPKEY; //Return your AdWhirl application key here

Also, add these two methods to pause and unpause the game if you have a game timer:

- (void)willDisplayWebViewCanvas {
isPaused = TRUE;
- (void)didDismissWebViewCanvas {
isPaused = FALSE;

You will also need to add some code in your timer method to pause timing if isPaused is true. For example, I have a tick event, which I bail out of immediately if isPaused is true.

I was also getting bunch of errors until I added a special line in the dealloc, to set the ad delegate to nil before you release it. So don't forget this part!!


if (rollerView) {
[rollerView setDelegateToNil];
[rollerView release];


And that's it! Hopefully using these few code snippets, you can avoid some of the learning I went through and get ads into your apps in less than an hour.

Obviously, you also need to go through the process on the AdWhirl web site to set up the ad providers, etc, but this is pretty simple. There can be some lag time for some of the providers waiting for codes and things to be emailed to you, but it does not take much of your time to submit the requests.

I hope this is a pretty complete overview. If you have questions, please feel free to send me a note. Good luck!!


Jason said...

Thanks for pointing out how to improve our developer onboarding experience. We made sure to include cut-and-paste friendly code samples to our developer wiki. By loging into your account from http://www.quattrowireless.com you can access the latest iPhone SDK along with a wiki link that contains step by step integration instructions and cut-and-paste code samples.

Jason St. Pierre
Quattro Wireless

jtabernik said...

This is a nice addition. Thanks for the update!

Anonymous said...

Hello, I am getting a few errors when I tried integrating AdWhirl into my app. I was hoping you could help me out.
here is a screenshot of the errors:

jtabernik said...

loganbest88, I have not seen either of these errors. I would recommend getting in touch with the folks at AdWhirl on this. If they haven't seen the errors before, let me know. Good luck!

Post a Comment