集成插屏广告

在集成该文档之前,请务必确保您已经集成了 basic integration 文档。

插屏广告属于全屏广告。一般在关卡过渡,应用开始等节点出现。一般来说插屏广告,用户可选择关闭,并在关闭后返回应用。

创建Interstitial Ad实例

  1. 请先导入 VungleAdsSDK 并创建一个 VungleInterstitial变量在您的ViewController.swift 文件中 (或者 Objective-c的ViewController.h文件).
    SwiftObjective-C
    import UIKit
    import VungleAdsSDK
    
    class LOInterstitialViewController: UIViewController {
        private var interstitialAd: VungleInterstitial?
  2. 添加以下代码来创建 VungleInterstitial 实例。请使用您的Placement ID来创建 VungleInterstitial实例。
    SwiftObjective-C
    self.interstitialAd = VungleInterstitial(placementId: <YOUR_PLACEMENT_ID>)
    self.interstitialAd?.delegate = self

下载Interstitial Ad

  1. 请参考以下代码来下载广告
    SwiftObjective-C
    self.interstitialAd = VungleInterstitial(placementId: <YOUR_PLACEMENT_ID>)
    self.interstitialAd?.delegate = self
    self.interstitialAd?.load()

播放Interstitial Ad

  1. 当广告加载好后,您可以调用 present(with: <YOUR_ViewController>)来展示广告
    SwiftObjective-C
    self.interstitialAd?.present(with: <YOUR_ViewController>)

注册Delegate

通过delegate的各个方法来监听各个事件

SwiftObjective-C
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")
    }
}

测试Interstitial Ad

您可以通过两种方式来测试插屏广告: 1.将您的应用在Dashboard中设置为Test Mode。 2. 在Dashboard中,将您的设备广告ID添加到应用的Test Device列表中。详情请查看 Test Your Integration: Test Mode and Test Devices.

更多

代码范例:

Questions?

Need further assistance, feel free to reach out to us, we’re here to help!

这篇文章有帮助吗?