iOS Development-Implant ads (IAd, admob instance)

Source: Internet
Author: User
Tags uikit admob

Embedding ads in apps is a great way to make a profit.

Here are two approaches to mainstream. IAd, Admob


First mark a very specific PDF. http://pan.baidu.com/share/link?shareid=1656439633&uk=1394536315&fid=406566606116897

One. Iad

1. Need to increase iad.framework

2.. h file additions such as the following code

#import <UIKit/UIKit.h>  #import <iAd/iAd.h>  

3.. m file additions such as the following code


#import "ViewController.h"    @interface viewcontroller ()  @property (nonatomic,strong) Adbannerview *adview;  @end    @implementation Viewcontroller    -(void) viewdidload  {      [super viewdidload];      Self.adview = [[Adbannerview alloc]initwithframe:cgrectmake (0, +, +)];      Self.adView.requiredContentSizeIdentifiers = [Nsset setwithobject:adbannercontentsizeidentifierportrait];      Self.adView.currentContentSizeIdentifier = adbannercontentsizeidentifierportrait;            Self.adView.delegate = self;      [Self.view AddSubview:self.adView];  }    -(void) Bannerviewwillloadad: (Adbannerview *) banner{      NSLog (@ "Bannerviewwillloadad");  }    -(void) Bannerviewdidloadad: (Adbannerview *) banner  {      NSLog (@ "Bannerviewdidloadad");  }    -(void) Bannerview: (Adbannerview *) banner didfailtoreceiveadwitherror: (NSERROR *) error  {      NSLog (@) Didfailtoreceiveadwitherror ");  }  

:







Two. Admob

1. Additional third-party documentation is required, as well as the following framework


2.

#define ADID @ "xxxxxxx"  //Set a own global ID

3.. h file additions such as the following code
#import <UIKit/UIKit.h>  #import "GADBannerView.h"  @interface Admobdefaultviewcontroller: Uiviewcontroller  {      gadbannerview *adview;  }

3.. m file additions such as the following code
-(void) viewdidload  {      [super viewdidload];      Additional setup after loading the view, typically from a nib.            Create A view of the standard size in the bottom of the screen.      ADView = [[Gadbannerview alloc]                     initwithframe:cgrectmake (0.0,self.view.frame.size.height-gad_size_ 320x50.height,gad_size_320x50.width,gad_size_320x50.height)];            Adview.adunitid = adid;//Call id            adview.rootviewcontroller = self;      Adview.backgroundcolor = [Uicolor yellowcolor];      [Self.view Addsubview:adview];            [ADView loadrequest:[gadrequest request];  }




3.

AdMob Interstitial ads


. h File Codes
#import <UIKit/UIKit.h>  #import "GADInterstitial.h"  #import "GADInterstitialDelegate.h"    @ Interface interadmobviewcontroller:uiviewcontroller<gadinterstitialdelegate>    @property (nonatomic, Retain) gadinterstitial *interstitial;    @end

. m file Codes
-(void) viewdidload  {      [super viewdidload];            Self.interstitial = [[Gadinterstitial alloc] init];      Self.interstitial.delegate = self;      Self.interstitial.adUnitID = ADID;            [Self.interstitial loadrequest: [self createrequest];        }    -(Gadrequest *) createrequest {      gadrequest *request = [gadrequest request];            Make the request for a test ad. Put in a identifier for the simulator as      //well as any devices you want to receive test ads.      request.testdevices =      [Nsarray arraywithobjects:       //Todo:add your Device/simulator test identifiers here. They was       //printed to the console when the app is launched.       Nil Nil];      return request;  }    -(void) Interstitialdidreceivead: (gadinterstitial *) interstitial {      [interstitial Presentfromrootviewcontroller:self];  }



iOS Development-Implant ads (IAd, admob instance)

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.