Add Google Admob in IOS Apps

On February 25, 2013, in iPhone iPad Object-C, Make Money Online, by James Liu

In IOS platform, Apple also provides a way to monetize IOS apps by iAd. However, the low fill rate is really a headache problem. Hence, Admob for IOS application is alternative way to make money from your apps. Admob provides a wide support for all mobile platforms, including Android apps, iPad apps, iPhone apps and Windows Phone apps. In post, Add Google Admob in Android Application, I give an example to show how to monetize android apps by Admob. Here, I will show you how to implement Google Admob in IOS apps.

Add Admob in iOS App

Add Admob in iOS App


AdMob can show 4 types of advertisement size:

Size Name Device
320×50 Standard banner phones and tablets
300×250 Medium Rectangle Tablets
468×60 Full-Size Banner Tablets
728×90 Leaderboard Tablets

In this example, I will use the example source code from RSS reader app tutorial. RSS reader app is a table which will show the first five posts from my website and I will insert an Admob standard banner into UITableView header and UITableView footer. To add the AdMob in iPhone Application, we have to create a AdMob account, download the Google AdMob Ads SDK for IOS and add the SDK in IOS app project.

add google admob sdk to project

add google admob sdk to project

Add AdMob Ads Banner to UITableView Header

GADBannerView is simply a UIView subclass. So it is very simple to insert AdMob standard banner into UITableView header, just like putting a UIView in the table header. Here is the source code example to show you how to add GADBannerView into UITableView header. The following code should be put in UITableViewController or its subclass.

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    // Create a view of the standard size at the top of the screen.
    // Available AdSize constants are explained in GADAdSize.h.
    GADBannerView *bannerView_ = [[GADBannerView alloc] initWithAdSize:kGADAdSizeBanner];
    
    // Specify the ad's "unit identifier." This is your AdMob Publisher ID.
    bannerView_.adUnitID = @"a15120dbc353a5f";
    
    // Let the runtime know which UIViewController to restore after taking
    // the user wherever the ad goes and add it to the view hierarchy.
    bannerView_.rootViewController = self;
    
    // Initiate a generic request to load it with an ad.
    [bannerView_ loadRequest:[GADRequest request]];
    
    return bannerView_;
}

-(float)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    // admob ad size height
    return 50.0;
}

Add AdMob Ads Banner to UITableView Footer

Using the same concept, we can also insert AdMob ads Banner into UITableView Footer as well. Here is the example code.

Add iOS Development Framework

Adding the SDK to project is not enough to show AdMob in your IOS apps. We also need to add several IOS development frameworks. Here are the frameworks needed by AdMob 6.3.0.

  • StoreKit
  • AudioToolbox
  • MessageUI
  • SystemConfiguration
  • CoreGraphics
  • AdSupport

Add iOS Development Framework

How to Add Google Admob in iOS5.0 with Xcode 4.2?

If you are using Xcode 4.2 with IOS5.0 sdk, you will meet the following building error:

Undefined symbols for architecture armv7:
“_SKStoreProductParameterITunesItemIdentifier”, referenced from:
-[GADOpener openInAppStore:fallbackURLString:] in libGoogleAdMobAds.a(GADOpener.o)

This is because the AdSupport framework is missing. However, this framework is only included in iOS 6.0 and later. Hence, there are two ways to solve the problem.

  • Copy iOS6.0 SDK into Xcode 4.2
  • Using Old Admob SDK which is compatible with iOS 5.1

How to add iOS 6.0 SDK into Xcode 4.2

Here I will use the first approach. Because I am using Mac OS 10.6.8, or Mac OS Leopard, the latest Xcode version is 4.2.0. I am gonna use the same way to update iOS6.0 SDK, in which I update to iOS5.0 SDK. Here are the steps:

  • Download the latest Xcode installation file, for example, Xcode 4.5.2.dmg
  • Double click to mount the DMG
  • Right click on Xcode icon and select “Show Package Contents”
  • Or if you have another Mac OS which can run Xcode 4.5, you can directly right click on Xcode icon and select “Show Package Contents”
  • Go into path “Contents/Developer/Platforms/iPhoneOS.platform/DeviceSupport”
  • Copy the corresponding folder, for example, folder “6.0”
  • Paste the copied folder in the equivalent place on your Snow Leopard Mac
  • Go into path “Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/”
  • Copy the corresponding sdk folder, for example, “iPhoneOS6.1.sdk”, and paste in the same place in your xcode 4.2 folder
  • Go into path “Contents/Developer/Platforms/iPhoneOS.platform”
  • Copy the file “version.plist” and paste in the same place in your xcode 4.2 folder
  • Restar your xcode

After above step, we add the SDK 6.0 to the Xcode 4.2 successfully. Now we can add the missing framework to our project.

AdMob in IOS Apps Compile Error and Solution

There are some errors we may meet when we build the Admob in IOS apps. For example,

Terminating app due to uncaught exception ‘NSInvalidArgumentException’, reason: ‘-[GADObjectPrivate changeState:]: unrecognized selector sent to instance 0xfe7a280’

To solve the above compile error, we need to add a build settings in “other linker flags”. Here is the step show you how to add building flag in “Other Linker Flags” in build settings.
1. Going to the IOS app project, build setting section. Type “Other Linker Flags” in search field. You will see the following result.

Add Other Linker Flags in Build Settings 1

Add Other Linker Flags in Build Settings 1

2. Double clicking the “Other Linker Flags” and show the setting field. Clicking plus icon in the setting field to add linker flags.

Add Other Linker Flags in Build Settings 2

Add Other Linker Flags in Build Settings 2


Add Other Linker Flags in Build Settings 3

Add Other Linker Flags in Build Settings 3


Add Other Linker Flags in Build Settings 4

Add Other Linker Flags in Build Settings 4

Google Admob with RSS Reader iPhone App Source Code $5.99

You will get whole iPhond Rss Reader App source code at $5.99. It is fully functional, and embedded the Google AdMob module by default. With this source code, you can do everything you want:

  • Load your website rss feed;
  • Monetize the app with your own AdMob publish id;
  • Use the source code in your own project;
  • Publish this app with your apple developer account;



4 Responses to “Add Google Admob in IOS Apps”

  1. ghouse says:

    – (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    // Create a view of the standard size at the top of the screen.
    // Available AdSize constants are explained in GADAdSize.h.
    GADBannerView *bannerView_ = [[GADBannerView alloc] initWithAdSize:kGADAdSizeBanner];

    // Specify the ad’s “unit identifier.” This is your AdMob Publisher ID.
    bannerView_.adUnitID = @”a15120dbc353a5f”;

    // Let the runtime know which UIViewController to restore after taking
    // the user wherever the ad goes and add it to the view hierarchy.
    bannerView_.rootViewController = self;

    // Initiate a generic request to load it with an ad.
    [bannerView_ loadRequest:[GADRequest request]];

    return bannerView_;
    }

    The above code is crashing the app what to do.

    _WebTryThreadLock(bool), 0x1d171ea0: Tried to obtain the web lock from a thread other than the main thread or the web thread.

  2. James says:

    Hi ghouse,

    I have double checked my project. There is no any problems for loading AdMob Ads.

    I think there is something wrong in your class usages. I recommend you can download and try my whole project.

    Thanks

  3. boomdigit says:

    Hey man, great tutorial unfortunately when I try to run via simulator I still get Adsupport not found even after following your steps for 6.0 on xcode 4.2. I have tried setting it as optional but no go..always fails to build and gives me the adsupport error.

    • James says:

      Hi,

      Do you set your project “Deployment Target” to 6.0? In my project, I have set “AdSupport.framework” as “Required.

Leave a Reply

Premium WordPress Themes

Weboy