Although in App It's a relatively low-level way of commercialization to add advertising to profit , But for individual developers or small team developers , Make an easy to use free gadget ( Take a chestnut ), Add some ads to it , If you use more people , It can also bring some considerable income . The user didn't pay , It's convenient , Developers have also been rewarded :)

I'm personally out of consideration for money and for money Google The trust of the , I chose AdMob This platform comes from App Put an advertisement in ( Access requires a ladder , The ladder is SS The best user is the global agent , Automatic agents is too laggy to access. ).

For now , I'm still not very good at moving App Advertising , So it's not recommended iAd( It seems that we still do not support Chinese mainland. ? I heard a while ago Apple A hundred or so people were disbanded iAd department ?) Some other platforms in China have also heard about it , But I didn't try , If you know what other good ones can be on the move App Advertising platform on the Internet , Comments are also welcome , Communicate together ~

technological process

1. First , You have to have one Google account number , Sign in AdMob
2. After go in , Click the settings button in the upper right corner of the website , Fill in all kinds of information , What call 、 mailbox 、 Address or something .

AdMob Screenshot of website

Be careful , The address should be the real address , stay Google Before I send you the money , He wants to send you a physical letter , There is a PIN code , You're going to put this PIN Code input to AdMob Corresponding position on the website ,Google Will start your remittance . I've verified my identity now , There's no way to take a screenshot , Fortunately, this website is not complicated , Just a few pages . Be prepared not to receive this letter ( China, including me N Many developers can't get this letter , I don't know if it's the postal issue ), If 1 I haven't received this letter for three months , You can apply again Google Mailing letters , All in all 3 Second chance ,3 A month later , I haven't received the letter yet , I.D. photos can be uploaded ( That's what I am ), then Google It's going to be very fast ( How many hours was that ) Through this request . After all, it took three months , If you fill in the address exactly the first time , If you're lucky , Sure 1 Let's go in a month Google I'm ready to pay you . The payment rule is to make statistics once a month , If it comes to 100 dollar , Just remit money , Otherwise, it will be included in next month , Until I have enough 100 dollar , The time of remittance is next month 21 Number . Like you 1 The month earned 30 The knife ,2 You don't get any money every month ,2 The month earned 110 The knife ,3 Of the month 21 Number Google It'll take all the money you make 140 All the knives are remitted to you .

3. The following process will not be repeated , It's just going AdMob Add an app to it , Get a similar one app-key The ID of (AdMob Inside is called ca-app-pub, Each advertisement corresponds to an identification code , One App You can add more than one banner ad or insert ad , One App It can correspond to multiple identification codes ), hold GoogleMobileAds.framework download , Take a look at the sample code , It's integrated into App 了 . This is the address

Banner advertisement and insert advertisement

Developers in App When advertising is added to , Try to avoid boring users very much . If your App Help users solve the problem , It doesn't matter if the user looks at the advertisement , It's a matter of fact that someone has solved the problem at hand , But the full screen ads kept popping , That's not good , The user may be angry App Delete .

On the left is a banner advertisement On the right is an insert

The advantage of banner advertising is that , Although it takes up part of the user's screen space , But as long as you don't click it , It does not affect other operations of the user , As long as your banner doesn't block anything , So this banner is not only eye-catching , For users App Basically no impact .

And insert type advertisement appears in the form of pop-up window , Users need to go to the top left or right corner and click the close button , It's more annoying than banner ads ( Anyway, I think so ), It should be said that this is a slightly serious interruption to the users App Used by . But the good thing is , Insert ads are in the form of full screen pop-up , It doesn't affect your design App Purity of interface , Let you have 100% Space to show you need to layout in UI Things in , Like you made one UI Application of minimalism , Whole App It's all pure black + Pure white , At this time, add a banner advertisement with complex colors , It's very affecting the impression .

There's also a situation where you want your users to pay to get rid of advertising , It can be in App Add a paid in order to buy advertising , Users can also be encouraged to pay to upgrade to the advanced version , In this case, you can try adding both banner ads and insert ads . Some of the users are interested in you App Demand , I don't want to be disturbed by advertisements , You can choose to pay . But in this case , We can think that one of the purposes of adding ads is to disturb users , Forcing users to pay , So it should be appropriate , Don't pop up ads too often , It's really annoying .

Code skills of display advertisement

1. stay UITableView Banner ads at the bottom

var admob = GADBannerView()
// Set up GADBannerView Of frame、 Set up advertisements ID、 Load ad request
self.tableView.contentInset = UIEdgeInsetsMake( 0, 0, admob.frame.height, 0)

The code in the comments section can be Reference here , This code means let UITableView The scrollable content area of shrinks at the bottom , The contraction length is banner Height of advertisement . This drags the user up all the time UITableView Until the end , You can make its draggable area larger than before , It won't be covered by advertisements UITableView The last few lines of .

If your UITableView It exists in UITableViewController Medium , that UITableView Of frame It's not adjustable , So through the code above , We can easily avoid advertising blocking the original content . And even if your UITableView It exists in UIViewController Medium , That is this. UITableView You added it yourself , You can adjust it as you like frame, I still suggest that you use the above method , Instead of putting UITableView Of frame The small , To make room for advertising . Because your ads don't always show up , Maybe the user blocked your advertisement , It may also be that the network condition is not good , At this time, your advertisement can't be displayed anyway , Users should be given more screen space to display UITableView The content of .

2. Use the timer to poll the loading status of plug-in ads

It's not used properly here “ polling ” The word , It's just as well that we all agree .
If you want to pop up an insert , that Google The example code is as follows

How to create GADInterstitial
Media resources 、 Initialize the resource and load it with the advertisement

Display insert advertisement

The logic here is : Don't disturb the process of users playing games , Loading ads silently in the process of users playing games , Wait for the end of a game , If the ad is loaded at this time , Just pop up the ads .

But the reality is , Our app may not be a game , There is no such obvious similarity Completed a game The end of such a paragraph . At this point, you may want to see every 30 Second pop-up a plug-in advertising , However, this advertisement may be the second one 40 Seconds to load it , And that leads to this : Even though you set up 30 Show ads once per second , however 30s The ads didn't load well when I was in the market , It didn't show up ,60s It's showing up when I'm in 40s Ads loaded when . And a more ideal scenario is :30s Failed to load good ads when it was finished , We'll start polling , Until the ad is loaded , That is to say 40s when , Show the advertisement , And then set number 70s Show your next ad when you're ready .

Here is a sample code , The logic of advertising here is : Every time 60 Show an advertisement every second , If it comes to this moment , The ads didn't load well , Set the timer every day 3 Seconds to check whether the advertising resources are ready , Until the ad is loaded , Display advertising , Then set the 60 The next advertisement will appear in seconds .

import UIKit

class ExampleViewController: UIViewController {

    // AdMob  Insert ads 
var adInterstitial = GADInterstitial(adUnitID: "ca-app-pub-xxxx/xxxx")
// Timer
var timer = NSTimer() override func viewDidLoad() {
super.viewDidLoad() // initialization AdMob Insert ads
let gadRequest1 = GADRequest()
self.addTimerToShowAd(3) // 3 Polling once a second until the first time the ad is displayed
} override func didReceiveMemoryWarning() {
} private func addTimerToShowAd( 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 {
// Ads loaded successfully , Display advertisement , Reset timer
}else {
// The ad did not load successfully , Start 3 Fast polling per second

The timer in the above code , Not in this article , If it's hard to watch , Feel free to comment below , I can also write another article about timers . About private and @objc The key words section can be referred to My previous article .

writing /KyXu The great devil ( Jane book author )
Link to the original text :
The copyright belongs to the author , Please contact the author for permission to reprint , And mark “ Jane book author ”.

【iOS Development 】 stay App Add AdMob advertisement - Introduction and programming skills of more related articles

  1. Share Ionic Development Hybrid App Problems encountered in and post release iOS/Android In every way

    This article mainly collates the recent use of Ionic Development  Hybrid App Some difficulties encountered in the process and post release generation iOS and Android All kinds of problems in the process of edition . List of articles Ionic Introduction and project requirements introduction ...

  2. <iOS Development > And App On the shelf process (2017)

    This paper mainly introduces App On the shelf process , And some of the problems that you will encounter in the process of putting it on the shelves . One .App Preparation before putting on shelves . Before we get on the shelf , Developers need to have an apple developer account , Please read the application process of Apple Developer account registration for details . This article is under the premise of having a developer account ...

  3. iOS Development series --App Extended development

    summary from iOS 8 Start Apple Introduced extension (Extension) It is used to enhance the interaction between system application services and applications . It allows you to customize your keyboard . The development of system services, such as system sharing and integration, has become possible .WWDC 2016 Many more ...

  4. IOS Development - promote app The performance of the 25 Suggestions and tips

    Preface This article introduces the summary of the author's development work 25 individual iOS Development tips, I read this article many years ago . Benefit a lot from it , Basically every one of them tips I've used it in my application development . Today, I'd like to sort out and forward this article again , Learn with you , Regardless of ...

  5. iOS From health app Get the number of steps information in

    It's not necessary for us to count the number of steps ,iOS Bring your own health app We've made statistics on the number of steps We just use HealthKit Framework from health app You can get this data information from 1. As shown in the figure below stay Xcode Open in Hea ...

  6. iOS Time in the development of animation ( survey )

    One . introduction stay iOS When using animation in development , Can be animated by duration.speed.begintime.offset attribute , To set the duration of the animation . Speed . Starting time and starting offset . Use a simple example to illustrate the function of each parameter ...

  7. android Insert in application admob advertisement

    Step One  land admob, Registered users Direct landing, use google Login with account number of Step Two land admob after , In site and application options Select and add and ...

  8. iOS Development RunLoop Study : One :RunLoop Brief introduction

    One :RunLoop A brief introduction #import "ViewController.h" @interface ViewController () @end @implementatio ...

  9. ( turn )iOS Development , Mixed use in Engineering ARC He Fei ARC

    [ Prerequisite knowledge ] ARC:Automatic Reference Counting, Auto reference count Developing iOS 3 And previous versions of the project, we are responsible for using reference count to manage memory , Like manual retain. ...

Random recommendation

  1. gulp Automated build

    Recently in use gulp Help me build some technology blocks automatically , It feels cool. , So the gulp Take notes of the steps , recorded ... First understand what is gulp? My understanding is a tool and automated , It can help you translate the syntax of some front-end technologies into the current ...

  2. IIS The design of the site under the virtual directory web.config Connection with root site web.config Conflict resolution

    IIS7.5 Deploy virtual directory under site on , The item prompt in the virtual directory conflicts with the configuration of the parent node ., Node and node <system.web> The connection between the node and the primary site <system.web> Conflict resolution : Under the site ...

  3. Extract QQ from iPhone and analyze it

    QQ is one of the most popular chat App in the world. Now let me show you how to extract QQ from iPho ...

  4. POJ 1542 Atlantis( Line segment tree area and )

    Topic link : Refer to the website : ...

  5. MS-SQL Server A complete collection of string processing functions

    MS-SQL Server A complete collection of string processing functions   select You can only use sql Functions operate on fields ( link sql server), select Field 1 from surface 1 where Field 1.Index ...

  6. ubuntu(16.04.01) Study -day1

    1. modify root User password sudo passwd root Follow the prompts to set . 2. from Ubuntu 16.04 Start , The user can change the position of the starter , You can move the launcher to the bottom of the screen , But it can't be moved to the right or to the top . Open the terminal ...

  7. [Swust OJ 1094]-- Median ( Skillfully use set, Heap sort )

    Topic link : Time limit(ms): 1000 Memory limit(kb): 32768   Median ( Also known as the median , Britain ...

  8. Dubbo Introduction and example explanation ( turn )

    Lin Bingwen Evankaka Original works . Reprint please indicate the source Dubbo It's alibaba SOA The core framework of service-oriented governance , Every day for 2,000+ Service offerings 3,000,0 ...

  9. rabbitmq stay mac Installation on

    1. install brew open   perform ruby -e "$(curl -fsSL ...

  10. Katalon Studio The request response Chinese garbled solution

    Recently in use Katalon During the interface test, it is found that the Chinese returned in the request response message is garbled , This is because the system environment we used in the initial installation chose simplified Chinese , Lead to windows The default encoding format is GBK, however KS The encoding format of is UTF ...