Admob-ing “Chinese Girls” by code

Upon seeing the first admob ads from Paper Toss, the realization that mobile display ads have entered a new era hit home. The catch-phrases of yesterday like m-coupons and location based advertising have given way to new ecosystems of ad networks and interconnectivity. This post is a brief account of my first foray into enabling admob in an iPhone app, using the source code to “Chinese Girls”.


First of all, anyone should check out Admob’s developer site and create a free account. Before downloading the sample code one is required to fill in details about the app where ads would be served. I don’t think Admob actually check if the are authentic though, as there’s no way they can verify who the owner of the app is.

Screen shot 2009-11-29 at 3.08.19 PM


Having done all the form filling, a link to download the SDK would be given. Note that the developer key is dynamically embedded in the sample code itself, which means it would be a bad idea to take a binary passed on by a friend and use it directly without even changing the developer key in the source code.

Screen shot 2009-11-29 at 2.28.46 PM


The SDK contains some sample code and library files an app serving admob ads need to include. Admob code makes use of the TouchJSON framework so the binaries to that are given too.

Screen shot 2009-11-29 at 3.36.54 PM


From then on it’s simply following instructions in the README file for the integration. Now’s the time to open up the project file to “Chinese Girls” with Xcode.


The first step would be adding the necessary library code and headers to the project. Since Chinese Girls is a 3.0+ app, the couple of .a files have to be renamed (simply removing the “3_0″ suffix) and grabbed from the extras/folder instead:

Screen shot 2009-11-29 at 3.47.21 PM


The next step is simply adding required frameworks. Admob documentation explains that these some framework files are needed to be there for successful compilation only, and they should not add to the weight of the app.

Screen shot 2009-11-29 at 4.06.28 PM


Now comes the real integration. Suppose I want to have the ad showing at the bottom of the main menu page, I would need to make the ViewController class for that page an AdMob delegate.


Changes highlighted in MenuViewController.h:

Screen shot 2009-11-29 at 4.03.00 PM


Finally, some boiler plate delegate code would need to be added to the MenuViewController.m class itself. For testing, return YES in the useTestAd() function. These delegate methods were lifted directly from samples in the Admob SDK. Except some customizations were needed in the didReceiveAd method. To position the ad at the bottom of the page, the frame holding the ad was appended as a subview of mainView.

Screen shot 2009-11-29 at 4.33.36 PM


Then in loadView, we add the follow to initiate the ad request:

Screen shot 2009-11-29 at 3.58.33 PM


And that’s basically it. After making sure the code could compile, I fired up the app in simulator, then waited for a few seconds. At this time it is useful to check the console for the status of the ad request code.

Screen shot 2009-11-29 at 4.11.43 PM

Screen shot 2009-11-29 at 4.11.51 PM


Note that ad Admob app don’t really care about the existing visual elements, so as we could see, the info icon at the bottom of the screen got blocked and became inaccessible. Move it up 40px and a re-compilation makes it see the light of day again. However, I can already foresee that more complicated re-positioning logic would be required in the didReceiveAd() method when the screen composes of more elements.

Screen shot 2009-11-29 at 4.22.15 PM


So that wasn’t too hard. In the next post I shall be taking interstitial ads (video ads that appear between view transitions) for a spin and see whether that would call for greater integration efforts.

Share

Related posts:

  1. Does visual diff-ing help crawlers? In our line of work, the mission of improving performances of conventional web crawlers...

Leave a Reply

Get Adobe Flash playerPlugin by wpburn.com wordpress themes