iOS Swift - How to implement Google audio Ad Unit?

Viewed 142

I followed the following tutorial https://developers.google.com/interactive-media-ads/docs/sdks/ios/client-side in order to set google ads. The tutorial give an example with video ad which works great.

While changing the url to an audio url ad, nothing happened. It might be a problem with the url but I cant find any valid audio example to test it.

My question is if I might need to implement it different because its audio ad, or if someone has a valid audio ad for testing.

Here is my code:


static let AdTagURLString = "https://pubads.g.doubleclick.net/gampad/ads?iu=/43010785/99fm/app/special_only/Playlist_audio&description_url=https%3A%2F%2example.co.il&tfcd=0&npa=0&ad_type=audio&sz=1x1&gdfp_req=1&output=vast&unviewed_position_start=1&env=vp&impl=s&correlator="
    
    var adsLoader: IMAAdsLoader!
    var adsManager: IMAAdsManager!

    func requestAds() {
      // Create ad display container for ad rendering.
      let adDisplayContainer = IMAAdDisplayContainer(adContainer: self.view, viewController: self)
      // Create an ad request with our ad tag, display container, and optional user context.
      let request = IMAAdsRequest(
          adTagUrl: PlaylistViewController.AdTagURLString,
          adDisplayContainer: adDisplayContainer,
          contentPlayhead: contentPlayhead,
          userContext: nil)

      adsLoader.requestAds(with: request)
    }



extension PlaylistViewController : IMAAdsLoaderDelegate, IMAAdsManagerDelegate {
    
    func adsManager(_ adsManager: IMAAdsManager!, didReceive event: IMAAdEvent!) {
      // Play each ad once it has been loaded
      if event.type == IMAAdEventType.LOADED {
        adsManager.start()
      }
    }
    
    func adsManager(_ adsManager: IMAAdsManager!, didReceive error: IMAAdError!) {
      // Fall back to playing content
    }
 
    func adsManagerDidRequestContentPause(_ adsManager: IMAAdsManager!) {
      // Pause the content for the SDK to play ads.
    }

    func adsManagerDidRequestContentResume(_ adsManager: IMAAdsManager!) {
      // Resume the content since the SDK is done playing ads (at least for now).
    }
    
    func adsLoader(_ loader: IMAAdsLoader!, adsLoadedWith adsLoadedData: IMAAdsLoadedData!) {
      adsManager = adsLoadedData.adsManager
      adsManager.delegate = self
      adsManager.initialize(with: nil)
    }

    func adsLoader(_ loader: IMAAdsLoader!, failedWith adErrorData: IMAAdLoadingErrorData!) {
        debugPrint("Error loading ads: " + adErrorData.adError.message!)
    }
    
}
0 Answers
Related