Intégration d’iAD dans iOS


Introduction

iAD est une plateforme publicitaire lancée par Apple qui aide les développeurs à générer des revenus à partir d'applications.

Étapes de l'exemple

1. Créez une application simple basée sur View

2. Sélectionnez le fichier du projet, puis sélectionnez la cible, puis sélectionnez Frameworks et ajoutez iAd.framework.

3. Mettez à jour ViewController.h comme indiqué ci-dessous

#import <UIKit/UIKit.h>
#import <iAd/iAd.h>
@interface ViewController : UIViewController<ADBannerViewDelegate>
{
    ADBannerView *bannerView;
}
@end

4. Mettez à jour ViewController.m, comme indiqué ci-dessous

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    bannerView = [[ADBannerView alloc]initWithFrame:
    CGRectMake(0, 0, 320, 50)];
    // Optional to set background color to clear color
    [bannerView setBackgroundColor:[UIColor clearColor]];
    [self.view addSubview: bannerView];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - AdViewDelegates

-(void)bannerView:(ADBannerView *)banner 
 didFailToReceiveAdWithError:(NSError *)error{
    NSLog(@"Error loading");
}

-(void)bannerViewDidLoadAd:(ADBannerView *)banner{
    NSLog(@"Ad loaded");
}
-(void)bannerViewWillLoadAd:(ADBannerView *)banner{
    NSLog(@"Ad will load");
}
-(void)bannerViewActionDidFinish:(ADBannerView *)banner{
    NSLog(@"Ad did finish");

}
@end

Sortie

Exécutez l'application, et vous obtiendrez la sortie suivante :

iAdOutput

Autres extensions