iOS Dev adds AdMob ads to your APP-introduction and programming Tips

Source: Internet
Author: User
Tags admob

Objective


While advertising in the app is a low-level commercial way of making money, for individual developers or small team developers, it's easy to make a free gadget (with a chestnut) and add some ads to it, and if you use more people, you can bring some decent income. The user did not pay, got the convenience, the developer also got the return:)

I personally chose the AdMob platform to serve ads in the app based on money considerations and trust in Google (https://apps.admob.com access needs a ladder, the ladder is the best global agent for the SS user, and the automatic proxy will get a lot of cards).

For the time being, I'm still not very good at mobile app advertising, so it's not recommended to use IAD (as if it's still not supporting China?). I heard Apple disbanded the IAD department with bedrooms people a while ago. Some other domestic platform is also heard, but did not try, if you know what other good can be on the mobile app ads on the platform, also welcome comments, Exchange ~

Process


1. First, you need to have a Google account, log in to AdMob
2. After entering, click the Settings button in the top right corner of the website to fill in all kinds of information, such as phone, email, address, etc.


AdMob website


Note that the address to fill in the real address, before Google to send you a remittance, he will send you an entity letter, which has a PIN code, you want to enter this PIN code to the location on the AdMob website, Google will start you send you money. I have now verified the identity, no way, fortunately this site is not complex, just a few pages. Do not receive this letter preparation (including me in the domestic n many developers are not receiving this letter, do not know whether it is the issue of the post), if not received this letter 1 months, you can again apply for Google Mail, a total of 3 opportunities, 3 months later, has not received the letter, You can upload your ID photo (that's how I am), and then Google will pass this request at the speed (I was a few hours). But after all, waiting for three months, if you first accurate fill the address, the luck is very good, you can let Google in 1 months ready to pay for you. Payment rules are monthly statistics, if the 100 dollars, the remittance, otherwise counted in the next month, until the savings of 100 dollars, remittance time is next month 21st. For example, you earned 30 knives in January, February will not receive money, February earned 110 knives, March 21st Google will make you earn a total of 140 knives are remitted to you.

3. The next process is not to repeat, but to add an application to AdMob, to get a similar App-key identification code (AdMob is called ca-app-pub, each ad corresponds to a code, an app can be added to multiple banner ads or interstitial ads, An app can correspond to multiple identifiers, download the googlemobileads.framework, and look at someone else's sample code and integrate it into the app. This is the address.

Banner ads and interstitial ads


When developers add ads to the app, they're trying to avoid annoying users. If your app helps users solve the problem, then users look at the ads do not matter, they solve the problem at hand is a matter, but Fullscreen ads constantly play, it is also a bad eating, users may rage the app to delete.


Banner ads to the right for interstitial ads on the left


The advantage of banner ads is that while it takes up a portion of the user's screen space, it does not affect the user's other actions as long as you don't click on it, so as long as your banner doesn't obscure anything, it has little effect on the user's use of the app, except for an eyesore.

and interstitial ads are in the form of pop-up windows, users need to go to the upper left corner or the upper right corner to click the Close button to line, should be said to be more annoying than banner ads (anyway I feel that), it should be said that this is a slightly serious inconvenience to users of the use of the app. But the upside is that interstitial ads appear as full-screen pop-ups, which doesn't affect the purity of the app interface you've designed, giving you 100% of space to show what you need to lay out in the UI, like you've made a minimalist app, and the app is pure Black + white, Adding a banner ad with a complex color can affect the perception.

Another scenario is that you want your users to pay to get rid of ads, either by adding a paid-to-ad in the app, or by encouraging users to pay for upgrades to the premium version, in which case both banner and interstitial ads can be added. Some users have a need for your app, and don't want to be interrupted by ads, you can choose to pay. However, in this case, we can think that one of the purposes of adding ads is to disturb the user, forcing users to pay, so should be appropriate so far, do not pop ads too often, this is really annoying.

Code tips for displaying ads


1. Display banner ads at the bottom of UITableView

var admob = GADBannerView()// 设置GADBannerView的frame、设置广告ID、加载广告请求self.tableView.contentInset = UIEdgeInsetsMake( 0, 0, admob.frame.height, 0)

The code in the comment section can refer to here, which means that UITableView's scrollable content area shrinks at the bottom and shrinks in length to the height of the banner ad bar. This allows the user to drag the UITableView up and down until the end, so that its draggable area is larger than before, so that the advertisement will not obscure the last few lines of the 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 the ads to obscure the original content. And even if your uitableview is present in the Uiviewcontroller, that is, this uitableview is added yourself, you can adjust the frame arbitrarily, I still suggest you use the above method, instead of directly UITableView Frame small, to give ads out of position. Because your ads do not necessarily show out, it may be the user to block your ads, or the network is not good, at this time, anyway, your ads are not shown, should give users more screen space to display UITableView content.

2. Polling interstitial ad loading status with timer

It is not appropriate to use the word "polling" here, and everyone is just as good.
If you want to pop up an interstitial ad, the sample code that Google gives is the following


How to create a gadinterstitial
Media Resource, initialize the resource, and load it with the ad
Show interstitial ads


Here the display logic is: Do not disturb the user to play the process of the game, in the process of users playing the game silently loaded ads, and so the user once the game is over, if this time the ads loaded, the ads bounce out.

However, the reality is that our application may not be a game, and there is no such obvious place as the end of a paragraph such as completing a game like this. At this point you may want to pop up an interstitial ad every 30 seconds, but this ad may be 40 seconds before it is loaded, which leads to the following: Although you set a 30-second display of the ad, but the 30s when the ads did not load well, did not show up, 60s when the display of 40s when the ads loaded. And the better case is: 30s did not load good ads, we started polling, until the ads loaded, that is, 40s, the ads displayed, and then set the first 70s to show the next ad.

Here is a sample code, where the ad display logic is: every 60 seconds to display an ad, if at this point, the ad does not load well, set the timer every 3 seconds to see if the ad resource is ready, until the ads loaded, display ads, and then set up 60 seconds after the next ad.

ImportUIKitClassExampleviewcontroller:Uiviewcontroller {AdMob Interstitial adsvar adinterstitial =Gadinterstitial (Adunitid:"Ca-app-pub-xxxx/xxxx")Timervar timer =Nstimer ()OverrideFuncViewdidload() {Super.viewdidload ()Initializing AdMob interstitial adsLet GadRequest1 =Gadrequest ()Self.adInterstitial.loadRequest (GadRequest1)Self.addtimertoshowad (3)3 seconds poll until first show ad}OverrideFuncDidreceivememorywarning() {Super.didreceivememorywarning ()} privateFuncAddtimertoshowad(Showadtimeinterval:nstimeinterval) {Self.timer =Nstimer.scheduledtimerwithtimeinterval (Showadtimeinterval, Target:Self, selector:"Showad", UserInfo:Nil, repeats:True) [Nsrunloop.currentrunloop (). AddTimer (self.timer, Formode: nsrunloopcommonmodes)]}  @objc private func showad () {if  Self.adInterstitial.isReady {//ad successfully loaded, display AD, reset timer self)  Self.timer.invalidate () self.addtimertoshowad (60)}else {//ad did not load successfully, start 3 seconds a quick poll  Self.timer.invalidate () self.addtimertoshowad (3)}}}   

The above code on the timer aspect of the content, it is not written in this article, if you look at the hard words, welcome to comment below, I can also write an article about the timer. For the private and @objc keywords section, you can refer to one of my previous articles.



Wen/kyxu, the Great Lord (Jane book author)
Original link: http://www.jianshu.com/p/c55b8592d2a1
Copyright belongs to the author, please contact the author to obtain authorization, and Mark "book author".

iOS Dev adds AdMob ads to your APP-introduction and programming Tips

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.