IOS InApp 4.1.0
From AdLocus
前言
InApp 版位為最常見的版位,AdLocus 提供您 320x50, 300x250, 728x90 三種不同尺寸的選擇。
實作
- #import <AdLocus/AdLocus.h>
啟動版位
self.banner = [[ALBannerView alloc] initWithFrame:CGRectMake(0, 0, 320, 50)]; self.banner.key = @"請填入您的APP KEY"; self.banner.targeting = targeting; //(選擇性) 請參考 ALTargeting 設定 [self.banner setBannerAnimationType:AdLocusBannerAnimationTypeRandom]; [self.banner setAutoRefreshWithTime:15]; [self.banner requestAdViewWithDelegate:self]; [self.view addSubview:self.banner];
- 設定監聽
範例: ViewController.h
#import <UIKit/UIKit.h> #import <AdLocus/AdLocus.h> @interface ViewController : UIViewController <ALBannerViewDelegate> @property (nonatomic, strong) ALBannerView *banner; @end
範例: ViewController.m
#import "ViewController.h" @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; [self initAdLocusBannerView]; } - (void)initAdLocusBannerView { self.banner = [[ALBannerView alloc] initWithFrame:CGRectMake(0, 0, 320, 50)]; self.banner.key = @"請填入您的APP KEY"; ALTargeting *targeting = [ALTargeting new]; targeting.age = 30 // 30 歲 targeting.gender = ALGenderMALE; // 男性 // targeting.location = location; //透過 LocationManager 取得的位置 targeting.testMode = NO; //測試模式關閉 self.banner.targeting = targeting; //(選擇性) 請參考 ALTargeting 設定 [self.banner setBannerAnimationType:AdLocusBannerAnimationTypeRandom]; [self.banner setAutoRefreshWithTime:15]; [self.banner requestAdViewWithDelegate:self]; [self.view addSubview:self.banner]; }
若您需要監聽廣告互動結果
透過實作 ALBannerViewDelegate 監測廣告運行結果
- adViewDidReceiveAd
- adViewDidFailToReceiveAd
- (void)adViewDidReceiveAd:(ALBannerView *)view { NSLog(@"Receive AdLocus banner Ad."); } - (void)adViewDidFailToReceiveAd:(ALBannerView *)view error:(AdLocusError *)error { NSLog(@"Failed receive AdLocus banner Ad : %@", error); }