[iOS development] in the App to join the AdMob Advertising – Introduction and programming skills



I am out of money into consideration and trust in Google, select the AdMob as the platform for advertising in App (https://apps.admob.com access need a ladder, the ladder is the best global SS user agent, proxy automatic word access will be very card).

For now, I am still not very good at the mobile App advertising this one, so we do not recommend using iAd (as if still do not support mainland China? I heard a while ago Apple disbanded one hundred people of the iAd Department)? Some of the other domestic platform is heard, but did not try, if you know what other good can be placed on the mobile App advertising platform, but also welcome comments, together with the exchange ~!

Technological process


[iOS development] in the App to join the AdMob Advertising - Introduction and programming skills
AdMob website screenshot

note that the address to fill the real address before Google give you the money, he should mail a letter entity letter to you, there is a PIN code, you need to put the PIN code input to the corresponding location on the AdMob site, Google will start to give you the money you. I have now verified identity, no way to shoot, but fortunately this site is not complicated, so a few pages. Do not receive this letter (for domestic N developers including me, have not received the letter, do not know is not the problem, if post) 1 months did not receive the letter, can let Google mail application again, a total of 3 times, 3 months later, haven’t the receipt of the letter, you can upload photo ID card (I do), then Google will speed (I was a few hours) by the request. But after all, waiting for three months, if the first time you fill in the correct address, luck is very good, then you can let Google prepare for payment within 1 months. Payment rule is a census every month, if to $100, is included in the remittance, or next month, until the time is saved 100 dollars, money next month 21. For example, you earned 30 knives in January, will not receive money in February, earned a profit of $110, in the year of March, Google will make you a total of $21 in the 140 knives are sent to you.

During the next 3 will not go into, is nothing more than to add a AdMob application, get a similar app-key identification code (AdMob which is called ca-app-pub, each ad corresponds to an identification code, a App can be added to a plurality of banner ads or interstitial ads, a App can correspond to a plurality of identification codes), GoogleMobileAds.framework download, look at their sample code, are integrated into App. This is the address

Advertising inserts and banner ads


[iOS development] in the App to join the AdMob Advertising - Introduction and programming skills
left for the banner on the right for interstitial ads

banner advantage is that although the users to take up a part of the screen space, but as long as you don’t click on it, it will not affect the operation of other users, as long as you do not cover any advertising content, then this banner in addition to unsightly, has no effect on the users to use App.

While the page type advertisement is in the form of popups, users need to go to the upper left corner or right click the close button that should be said to be more than banner ads to dislike some (I think so), it should be said that this is a slightly serious disturb the user on the use of App the. But the advantage is that the interstitial ads appear in full screen pop-up form, it does not affect your App interface design of purity, let you have 100% of the space you need to show the layout in UI things, such as you do a UI application of minimalist, the entire App is pure black + white at this time, with a complex color banner ads, it is affecting perception.

There is a situation where you want your users to pay to remove ads, can be in App with a pay to purchase advertising, can also encourage users to pay to upgrade to advanced application version, can try banner ads and interstitials are added in this case. Part of the user on your App needs, and do not want to be repeatedly interrupted by advertising, you can choose to pay. But in this case, we can think of the purpose of advertising is to add one to disturb users, forcing users to pay, so it should be appropriate, not too frequent pop-up ads, this is really annoying.

Display advertising code skills

1 display banner ads at the bottom of the UITableView

Var AdMob = GADBannerView (GADBannerView, frame) / / set ID, set the advertising advertising loading request self.tableView.contentInset = UIEdgeInsetsMake (0, 0, admob.frame.height, 0)

The comment section of the code can refer to here, this code is meant to allow the contents of the UITableView rolling area at the bottom of the contraction, the length of the contraction of the height of the banner ads. In this way, the user has been dragging up until the end of the UITableView, you can let it drag and drop areas larger than before, so as not to allow advertising to cover the last few lines of UITableView.

If your UITableView is present in the UITableViewController, then the UITableView frame is not adjustable, so by the above code, we can easily avoid blocking the original content of advertising. Even if your UITableView is present in the UIViewController, the UITableView is added to your own, you can adjust the frame, I still suggest you use the above method, rather than directly to the UITableView frame, to make way for advertising. Because your advertising does not necessarily indicate the user may be advertising your shield, also may be the network condition is not good, this time anyway, your advertising also does not show up, should give users more screen space to display the contents of the UITableView.

Use 2 timer polling interstitials loaded state

Here is not very appropriate to use the word “polling”, everyone is good sense.
if you want to pop up a interstitials, then Google gives the example code is like the following

[iOS development] in the App to join the AdMob Advertising - Introduction and programming skills
how to create a GADInterstitial
media resource, initialize the resource and load it with an ad
[iOS development] in the App to join the AdMob Advertising - Introduction and programming skills
showed interstitial ads

display logic here is: don’t disturb users play games in the process, in the process of users playing the game, silently loading ads, users such as the end of a game, if the advertisement loaded, the ads play out.

The reality is, however, that our application may not be a game, and there is no such thing as the end of a paragraph that is so obvious that a game has been completed. You may want to pop up every 30 seconds a page type of advertising, but the advertising may be fortieth seconds before loading, which leads to: Although you set the display is an advertisement for 30 seconds, but when the 30s advertising does not loading, is not displayed when the 60s display advertising loading 40s. And the more ideal situation is: 30s can not load a good advertising, we began to vote until the advertising is loaded, that is, 40s, the ad displayed, and then set the first 70s to display the next ad.

Below is a sample code, advertising display logic here is: every 60 seconds to show an ad, if at this moment, no advertising loading, will set the timer every 3 seconds at a time of advertising resources are ready, until the advertisement loaded, display advertising, and then set the next 60 ads seconds later.

Import UIKit class ExampleViewController: UIViewController AdMob var adInterstitial {/ / insert = GADInterstitial (adUnitID: ca-app-pub-xxxx/xxxx) = NSTimer (timer / var timer) override func (viewDidLoad) super.viewDidLoad (AdMob) {/ / let = gadRequest1 initialization inserts (GADRequest) self.adInterstitial.loadRequest (gadRequest1) self.addTimerToShowAd (3) / 3 seconds at a time until the first polling show override func (didReceiveMemoryWarning) ad} {super.didReceiveMemoryWarning} (private) func addTimerToShowAd (showAdTimeInterval:NSTimeInterval) {self.timer = NSTimer.scheduledTimerWithTimeInterval (showAdTimeInterval, target:, sel F, selector: "showAd" userInfo:, nil, repeats:) true ([NSRunLoop.currentRunLoop).AddTimer (self.timer forMode: NSRunLoopCommonModes)] @objc private func (showAd)} {{/ / self.adInterstitial.isReady if advertising display advertising success, loading, reset the timer self.adInterstitial.presentFromRootViewController (self) self.timer.invalidate (self.addTimerToShowAd) (60)}else {/ / advertising is not successful loading. Fast start polling self.timer.invalidate 3 seconds once (self.addTimerToShowAd) (3)}}}

The contents of the above code on the timer, it is not written in this article, if you look at the effort, welcome to comment on the following, I can also write an article on the timer. About private and @objc keywords can refer to my previous article.