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)