在集成该文档之前,请务必确保您已经集成了 basic integration 文档。
插屏广告属于全屏广告。一般在关卡过渡,应用开始等节点出现。一般来说插屏广告,用户可选择关闭,并在关闭后返回应用。
创建Interstitial Ad实例
- 请先导入
VungleAdsSDK并创建一个VungleInterstitial变量在您的ViewController.swift文件中 (或者 Objective-c的ViewController.h文件).import UIKit import VungleAdsSDK class LOInterstitialViewController: UIViewController { private var interstitialAd: VungleInterstitial?#import "LOInterstitialViewController.h" #import <VungleAdsSDK/VungleAdsSDK.h> @interface LOInterstitialViewController () <VungleInterstitialDelegate> @property (nonatomic, strong) VungleInterstitial *interstitialAd; @end
- 添加以下代码来创建
VungleInterstitial实例。请使用您的Placement ID来创建VungleInterstitial实例。self.interstitialAd = VungleInterstitial(placementId: <YOUR_PLACEMENT_ID>) self.interstitialAd?.delegate = self
self.interstitialAd = [[VungleInterstitial alloc] initWithPlacementId:<YOUR_PLACEMENT_ID>]; self.interstitialAd.delegate = self;
下载Interstitial Ad
- 请参考以下代码来下载广告
self.interstitialAd = VungleInterstitial(placementId: <YOUR_PLACEMENT_ID>) self.interstitialAd?.delegate = self self.interstitialAd?.load()
self.interstitialAd = [[VungleInterstitial alloc] initWithPlacementId:<YOUR_PLACEMENT_ID>]; self.interstitialAd.delegate = self; [self.interstitialAd load:nil];
播放Interstitial Ad
- 当广告加载好后,您可以调用
present(with: <YOUR_ViewController>)来展示广告self.interstitialAd?.present(with: <YOUR_ViewController>)
[self.interstitialAd presentWith:<YOUR_ViewController>];
注册Delegate
通过delegate的各个方法来监听各个事件
extension LOInterstitialViewController: VungleInterstitialDelegate {
// Ad load events
func interstitialAdDidLoad(_ interstitial: VungleInterstitial) {
print("interstitialAdDidLoad")
}
func interstitialAdDidFailToLoad(_ interstitial: VungleInterstitial, withError: NSError) {
print("interstitialAdDidFailToLoad")
}
// Ad Lifecycle Events
func interstitialAdWillPresent(_ interstitial: VungleInterstitial) {
print("interstitialAdWillPresent")
}
func interstitialAdDidPresent(_ interstitial: VungleInterstitial) {
print("interstitialAdDidPresent")
}
func interstitialAdDidFailToPresent(_ interstitial: VungleInterstitial, withError: NSError) {
print("interstitialAdDidFailToPresent")
}
func interstitialAdDidTrackImpression(_ interstitial: VungleInterstitial) {
print("interstitialAdDidTrackImpression")
}
func interstitialAdDidClick(_ interstitial: VungleInterstitial) {
print("interstitialAdDidClick")
}
func interstitialAdWillLeaveApplication(_ interstitial: VungleInterstitial) {
print("interstitialAdWillLeaveApplication")
}
func interstitialAdWillClose(_ interstitial: VungleInterstitial) {
print("interstitialAdWillClose")
}
func interstitialAdDidClose(_ interstitial: VungleInterstitial) {
print("interstitialAdDidClose")
}
}
#pragma mark - VungleInterstitial Delegate Methods
// Ad load events
- (void)interstitialAdDidLoad:(VungleInterstitial *)interstitial {
NSLog(@"interstitialAdDidLoad");
}
- (void)interstitialAdDidFailToLoad:(VungleInterstitial *)interstitial
withError:(NSError *)withError {
NSLog(@"interstitialAdDidFailToLoad");
}
// Ad Lifecycle Events
- (void)interstitialAdWillPresent:(VungleInterstitial *)interstitial {
NSLog(@"interstitialAdWillPresent");
}
- (void)interstitialAdDidPresent:(VungleInterstitial *)interstitial {
NSLog(@"interstitialAdDidPresent");
}
- (void)interstitialAdDidFailToPresent:(VungleInterstitial *)interstitial
withError:(NSError *)withError {
NSLog(@"interstitialAdDidFailToPresent");
}
- (void)interstitialAdDidTrackImpression:(VungleInterstitial *)interstitial {
NSLog(@"interstitialAdDidTrackImpression");
}
- (void)interstitialAdDidClick:(VungleInterstitial *)interstitial {
NSLog(@"interstitialAdDidClick");
}
- (void)interstitialAdWillLeaveApplication:(VungleInterstitial *)interstitial {
NSLog(@"interstitialAdWillLeaveApplication");
}
- (void)interstitialAdWillClose:(VungleInterstitial *)interstitial {
NSLog(@"interstitialAdWillClose");
}
- (void)interstitialAdDidClose:(VungleInterstitial *)interstitial {
NSLog(@"interstitialAdDidClose");
}
测试Interstitial Ad
您可以通过两种方式来测试插屏广告: 1.将您的应用在Dashboard中设置为Test Mode。 2. 在Dashboard中,将您的设备广告ID添加到应用的Test Device列表中。详情请查看 Test Your Integration: Test Mode and Test Devices.
更多
代码范例: