iOS - Intégration iAd

iAd est utilisé pour afficher des publicités, diffusées par le serveur Apple. iAd nous aide à générer des revenus à partir d'une application iOS.

Intégration iAd - étapes impliquées

Step 1 - Créez une application simple basée sur la vue.

Step 2 - Sélectionnez votre fichier de projet, puis sélectionnez les cibles, puis ajoutez iAd.framework dans Choose frameworks.

Step 3 - Mettez à jour ViewController.h comme suit -

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

@interface ViewController : UIViewController<ADBannerViewDelegate> {
   ADBannerView *bannerView;
}
@end

Step 4 - Mettre à jour ViewController.m comme suit -

#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

Production

Lorsque nous exécutons l'application, nous obtenons la sortie suivante -