IOS显示插屏广告教程

编码前的准备

在阅读这篇教程之前,请先阅读 ios接入广告基础教程 了解 如何获得广告管理库 怎么添加广告管理库

编写接入广告代码

1.首先添加相关的头文件
 #import <KeymobAd/KeymobAd.h>
2.初始化Keymob
初始化Keymob管理库是调用其他广告功能函数的前提,必须先初始化才能做别的调用,下面是使用Keymob.com 服务的初始化方式
    [[AdManager sharedInstance] setController: self andListener: [[AdListener alloc] init]];
    [[AdManager sharedInstance] configWithKeymobService: @ "1" isTesting: YES];
3.加载广告
[[AdManager sharedInstance] loadInterstitial];
4.检查全屏广告是否加载成功
[[AdManager sharedInstance] isInterstitialReady];
5.展示全屏广告
[[AdManager sharedInstance] showInterstitial];
6.展示全屏广告过程
除了在接收成功事件里面直接调用showInterstitial外,都需要先检测广告是否加载成功再展示,一般代码片段如下
    if([[AdManager sharedInstance] isInterstitialReady]){
        [[AdManager sharedInstance] showInterstitial];
    }
7.处理广告事件
展示全屏广告可以在游戏结束,过关或者其他用户行为触发,也可以在广告接收成功的时候,下面是在事件中展示 的代码
#import "AdListener.h"
@implementation AdListener
- (void)onLoadedSuccess:(int) adtype withAdapter:(id<IPlatform>)adapter andData:(id)error{
NSLog(@"onLoadedSuccess%@ %d",[adapter platformName],adtype);
if(KM_AD_TYPES_INTERSTITIAL==adtype){ [[AdManager sharedInstance] showInterstitial]; } }
- (void)onLoadedFail:(int) adtype withAdapter:(id<IPlatform>)adapter andData:(id)error{
NSLog(@"onLoadedFail%@ %@ %d",error,[adapter platformName],adtype);
}
- (void)onAdOpened:(int) adtype withAdapter:(id<IPlatform>)adapter andData:(id)error{
NSLog(@"onAdOpened%@ %@ %d",error,[adapter platformName],adtype);
}
- (void)onAdClosed:(int) adtype withAdapter:(id<IPlatform>)adapter andData:(id)error{
NSLog(@"onAdClosed%@ %@ %d",error,[adapter platformName],adtype);
}
- (void)onAdClicked:(int) adtype withAdapter:(id<IPlatform>)adapter andData:(id)error{
NSLog(@"onAdClicked%@ %@ %d",error,[adapter platformName],adtype);
}
- (void)onOtherEvent:(int) adtype withAdapter:(id<IPlatform>)adapter andData:(id)error eventName:(NSString*)_eventName{
NSLog(@"onOtherEvent%@ %@ %d",error,[adapter platformName],adtype);
}
@end
    #import <Foundation/Foundation.h>
#import <KeymobAd/KeymobAd.h>
@interface AdListener : NSObject <IAdEventListener> @end

更多手机应用接入广告教程   qq交流群 310513042   返回首页