Integrate IAD banner in the app to monetize your display ads

Source: Internet
Author: User

If you've made a Super Bull X app. You may have one more thing to worry about. The app is good enough, how to make a profit? You can charge for users who download your app. It can also be completely free and then put ads in the app to make a profit. Now, unless an app is really non-useful, or famous, it's a fun game. Otherwise, users are generally not charged. The smart choice is free, integrated advertising. The profit of the advertisement is divided by Apple and the development of this joint. In general, developers accounted for 70% and Apple accounted for 30%. After all, Apple has set up a network of ad distribution.

Of course, there are a lot of developers choose to in the free version of the app in the ads, but also developed a fee but no advertising version. Non-advertising is generally called Lite version, free but there is advertising or not very full function. If users like your lite version, or they go back to pay to buy a full-featured ad-free version.

You can have a lot of options for inheriting ads. A variety of mobile advertisers will develop a bunch of SDK for you to use, integrated into the real ads can be. This is mainly about Apple's iad banner. Banner placement and related processing can be migrated to the banner processing of other AD platforms. The location of the banner is usually placed on the top or bottom. For a view without a tab bar, the banner can be placed at the bottom. You can also place it somewhere else in the view. It's just that the Apple is ready to do the trial.

Let's get down to the chase. First you have taken part in the 99-knife developer program. You will then need to apply for the IAD Network in your itunes connect account.

Go in and request the IAd Network on the next page.

Click the request button and you'll see a bunch of things and finally agree. You can only agree to join IAD. Once you've agreed, you'll go to the next page, setting up contact information, bank information, and tax information.

Set it up and wait for it to pass.

Inherit iad from your app

The following begins to inherit IAD from the app. The main point here is banner.

First, in Xcode5, select Create a project and select single View application.

The following, the project name and so on any kind of good, do not map.

The first thing to do when the project is built is the need to add the IAD framework to the project (of course not, and in the case of XCODE5 and iOS7, use the @import iad directly. The framework is automatically added without adding it manually. Refer to StackOverflow's answer in detail).

The following initializes our banner view:

#import "BVRootViewController.h" @import iAd;

@interface Bvrootviewcontroller () <adbannerviewdelegate>{
@property (Weak, nonatomic) Adbannerview *bannerview;
}
@implementation bvrootviewcontroller-(void) viewdidload{    [Super Viewdidload];        Adbannerview *bannerview = [[Adbannerview alloc] Initwithframe:cgrectmake (0, [UIScreen mainscreen].bounds.size.height -(a);    Bannerview.delegate = self;    Bannerview.alpha =. 0f;    [Self.view Addsubview:bannerview];
Self.bannerview = Bannerview;}

Add the IAD framework and add the banner view. In general, this can be used. However, this does not reach the fine control of the banner view. Therefore, after banner view is initialized, add the proxy, which is specified as self. In the agent you can tell when the ad will appear or appear on the interface. Or, a variety of reasons for the acquisition of advertising failure, when more ads can appear, whether the user clicked on banner ads two into full-screen mode of advertising display. The most important point, the advertisement is not you want to have, want to have can have. The appearance of the advertisement takes time, not immediately. So, before the first ad appears, this bare banner is best not to appear within the user's implementation. This banner is best hidden when there are many reasons why ads cannot be displayed. Setting the Alpha=0.0f,banner view is not visible. Then, in the proxy method, when the ad is ready for reality, set the alpha to 1 and the user is visible. Of course, to hide this banner you can set the Hidden=yes directly, or move the banner directly out of the viewable area. Any method can be, but here I chose to set the alpha=0.

There are five ways to adbannerviewdelegate a protocol. Using these methods, you can manage all aspects of the banner. The following methods are added to the code, and in each method body add NSLog(@ "%s", __pretty_function__); The name of the method where the output is. In this way, each method is used in the study.

-(void) Bannerviewwillloadad: (Adbannerview *) banner{    NSLog (@ "%s", __pretty_function__);}

According to Apple's good naming habit, you can see from the method name at a glance what this method does. This method is called when the ad is about to be loaded. Therefore, this method is called when the ad has not yet loaded in.

-(void) Bannerviewdidloadad: (Adbannerview *) banner{    NSLog (@ "%s", __pretty_function__);}

This method is called after the ad is loaded. This time the ad is ready to show. Then add the code to this method and let banner show it.

-(BOOL) Bannerviewactionshouldbegin: (Adbannerview *) banner willleaveapplication: (BOOL) willleave{    NSLog (@ "%s", __PRETTY_FUNCTION__);    return YES;}

This method is called when the user clicks banner. After the user clicks Banner, a modal view reality canvas will appear. When this canvas appears, any user-related activity needs to be paused. The return is yes, if the return is no, the user clicked the banner will not appear after the full screen ads.

-(void) Bannerviewactiondidfinish: (Adbannerview *) banner{    NSLog (@ "%s", __pretty_function__);}

This method is called when the full-screen advertisement exits. In this case, the full screen ad is paused when it appears and can start running.

-(void) Bannerview: (Adbannerview *) banner didfailtoreceiveadwitherror: (Nserror *) error{    NSLog (@ "%s", __pretty_ FUNCTION__);}

This method is very important. Call this method when no ads are distributed to the app. When this method is called, hide the banner so that there is no bare banner.

As you can see, the methods in protocol make it easier to deal with advertising-related things. Now, add all of the specific useful code mentioned earlier to each method.

-(void) Bannerviewdidloadad: (Adbannerview *) banner{    NSLog (@ "%s", __pretty_function__);        [UIView animatewithduration:.25f animations:^{        self.bannerView.alpha = 1.f;    }];}

Using a small animation here, let banner slowly appear in the user's field of vision. And then:

-(void) Bannerview: (Adbannerview *) banner didfailtoreceiveadwitherror: (Nserror *) error{    NSLog (@ "%s", __pretty_ FUNCTION__);        [UIView animatewithduration:.25f animations:^{        self.bannerView.alpha =. 0f;    }];}

The most important thing is done. The app's ads are ready to use.

So far so good. But it's not good enough. We need to add a timer to Banner view. Pause when the canvas is out and resume timing when exiting.

The first three properties are required to implement this function:

@property (Strong, nonatomic) Nstimer *timer; @property (assign, nonatomic) Nsinteger secondselapsed; @property (Assign, nonatomic) BOOL pausetimecouting;

Add the necessary initialization code inside the viewdidloaded:

-(void) viewdidload{    //initialization code    Nstimer *timer = [Nstimer scheduledtimerwithtimeinterval:1.0f target:self Selector: @selector (timeraction:) Userinfo:nil Repeats:yes];    Self.timer = timer;    self.secondselapsed = 0;}

At this point Xcode will give a warning. The selector we set up in Nstimer has not yet been implemented:

-(void) Timeraction: (ID) sender{    NSLog (@ "%s", __pretty_function__);}

In this method, the timer is executed at every second of the call. Here to determine whether the timing is required, if necessary, read the second increase one. Otherwise, the timer is paused.

-(void) Timeraction: (ID) sender{    NSLog (@ "%s", __pretty_function__);        if (!self.pausetimecouting) {        self.secondselapsed++;    }    else{        NSLog (@ "not counted");}    }

In the previous discussion of the proxy method, the method -(BOOL) Bannerviewactionshouldbegin: (adbannerview *) Banner willleaveapplication: ( BOOL) willleave will be called when the ad enters the full screen. Of course it's time to return yes. This time the timing needs to be paused. As long as you set pausetimecouting to Yes, you can achieve your goal:

-(BOOL) Bannerviewactionshouldbegin: (Adbannerview *) banner willleaveapplication: (BOOL) willleave{    NSLog (@ "%s", __PRETTY_FUNCTION__);        self.pausetimecouting = YES;        return YES;}

Of course, when is the time to start? When the full screen ad exits:

-(void) Bannerviewactiondidfinish: (Adbannerview *) banner{    NSLog (@ "%s", __pretty_function__);    self.pausetimecouting = NO;}

Here's the whole story.

It's a lot of developers ' choice to inherit the ads in the app. You may not be able to make a lot of money from advertising, but if you have a lot of people downloading your app, you can at least have an objective income. As you can see in this tutorial, integrated advertising is just a few lines of code. If there is something unclear, you can see Apple's official code. I hope this tutorial is helpful to you.

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.