IOS development-advertisement placement (iAd, Admob instance)

Source: Internet
Author: User
Tags admob

Advertising is a good way to make profits.

The following describes two mainstream methods. IAd, Admob


Mark a detailed pdf. Http://pan.baidu.com/share/link? Required id = 1656439633 & uk = 1394536315 & fid = 406566606116897

I. IAd

1. You need to add iAd. framework

2. Add the following code to the H file:

#import <UIKit/UIKit.h>  #import <iAd/iAd.h>  @interface ViewController : UIViewController<ADBannerViewDelegate> 

3. Add the following code to the. m file:


#import "ViewController.h"    @interface ViewController ()  @property (nonatomic,strong)ADBannerView *adView;  @end    @implementation ViewController    - (void)viewDidLoad  {      [super viewDidLoad];      self.adView = [[ADBannerView alloc]initWithFrame:CGRectMake(0, 64, 320, 50)];      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");  }  

:







II. Admob

1. Add third-party files and the following framework


2.

# Define ADID @ "xxxxxxx" // set your own global id

3. Add the following code to the H file:
#import <UIKit/UIKit.h>  #import "GADBannerView.h"  @interface AdmobDefaultViewController : UIViewController  {      GADBannerView *ADView;  }

3. Add the following code to the. m file:
-(Void) viewDidLoad {[super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. // Create a view of the standard size at 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 Advertisement
. H file code
#import <UIKit/UIKit.h>  #import "GADInterstitial.h"  #import "GADInterstitialDelegate.h"    @interface InterAdmobViewController : UIViewController<GADInterstitialDelegate>    @property(nonatomic, retain) GADInterstitial *interstitial;    @end

. M file code
- (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 an 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 are       // printed to the console when the app is launched.       nil nil];      return request;  }    - (void)interstitialDidReceiveAd:(GADInterstitial *)interstitial {      [interstitial presentFromRootViewController:self];  }



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.