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.

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.

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.

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:

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.

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:

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.

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

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.


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.

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.
Related posts:
- Does visual diff-ing help crawlers? In our line of work, the mission of improving performances of conventional web crawlers...

