[IOS ADS] Setup ads only if adTagUrl present

This commit is contained in:
Axel Vencatareddy 2022-11-17 12:12:50 +01:00
parent fa817264fc
commit 9386955ab0
2 changed files with 14 additions and 12 deletions

View File

@ -9,7 +9,7 @@ class RCTIMAAdsManager: NSObject, IMAAdsLoaderDelegate, IMAAdsManagerDelegate {
private var adsLoader: IMAAdsLoader! private var adsLoader: IMAAdsLoader!
/* Main point of interaction with the SDK. Created by the SDK as the result of an ad request. */ /* Main point of interaction with the SDK. Created by the SDK as the result of an ad request. */
private var adsManager: IMAAdsManager! private var adsManager: IMAAdsManager!
init(video:RCTVideo!) { init(video:RCTVideo!) {
_video = video _video = video
@ -24,7 +24,7 @@ class RCTIMAAdsManager: NSObject, IMAAdsLoaderDelegate, IMAAdsManagerDelegate {
func requestAds() { func requestAds() {
// Create ad display container for ad rendering. // Create ad display container for ad rendering.
let adDisplayContainer = IMAAdDisplayContainer(adContainer: _video, viewController: _video.reactViewController()) let adDisplayContainer = IMAAdDisplayContainer(adContainer: _video, viewController: _video.reactViewController())
let adTagUrl = _video.getAdTagUrl() let adTagUrl = _video.getAdTagUrl()
let contentPlayhead = _video.getContentPlayhead() let contentPlayhead = _video.getContentPlayhead()
@ -35,11 +35,11 @@ class RCTIMAAdsManager: NSObject, IMAAdsLoaderDelegate, IMAAdsManagerDelegate {
adDisplayContainer: adDisplayContainer, adDisplayContainer: adDisplayContainer,
contentPlayhead: contentPlayhead, contentPlayhead: contentPlayhead,
userContext: nil) userContext: nil)
adsLoader.requestAds(with: request) adsLoader.requestAds(with: request)
} }
} }
// MARK: - Getters // MARK: - Getters
func getAdsLoader() -> IMAAdsLoader? { func getAdsLoader() -> IMAAdsLoader? {
@ -56,7 +56,7 @@ class RCTIMAAdsManager: NSObject, IMAAdsLoaderDelegate, IMAAdsManagerDelegate {
// Grab the instance of the IMAAdsManager and set yourself as the delegate. // Grab the instance of the IMAAdsManager and set yourself as the delegate.
adsManager = adsLoadedData.adsManager adsManager = adsLoadedData.adsManager
adsManager?.delegate = self adsManager?.delegate = self
// Create ads rendering settings and tell the SDK to use the in-app browser. // Create ads rendering settings and tell the SDK to use the in-app browser.
let adsRenderingSettings: IMAAdsRenderingSettings = IMAAdsRenderingSettings(); let adsRenderingSettings: IMAAdsRenderingSettings = IMAAdsRenderingSettings();

View File

@ -217,7 +217,7 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
]) ])
if currentTimeSecs >= 0 { if currentTimeSecs >= 0 {
if !_didRequestAds && currentTimeSecs >= 0.0001 { if !_didRequestAds && currentTimeSecs >= 0.0001 && _adTagUrl != nil {
_imaAdsManager.requestAds() _imaAdsManager.requestAds()
_didRequestAds = true _didRequestAds = true
} }
@ -310,10 +310,12 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
self.setAutomaticallyWaitsToMinimizeStalling(self._automaticallyWaitsToMinimizeStalling) self.setAutomaticallyWaitsToMinimizeStalling(self._automaticallyWaitsToMinimizeStalling)
} }
// Set up your content playhead and contentComplete callback. if _adTagUrl != nil {
self._contentPlayhead = IMAAVPlayerContentPlayhead(avPlayer: self._player!) // Set up your content playhead and contentComplete callback.
self._contentPlayhead = IMAAVPlayerContentPlayhead(avPlayer: self._player!)
self._imaAdsManager.setUpAdsLoader() self._imaAdsManager.setUpAdsLoader()
}
//Perform on next run loop, otherwise onVideoLoadStart is nil //Perform on next run loop, otherwise onVideoLoadStart is nil
self.onVideoLoadStart?([ self.onVideoLoadStart?([
@ -814,7 +816,7 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
} }
// MARK: - RCTIMAAdsManager // MARK: - RCTIMAAdsManager
func getAdTagUrl() -> String? { func getAdTagUrl() -> String? {
return _adTagUrl return _adTagUrl
} }
@ -823,11 +825,11 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
func setAdTagUrl(_ adTagUrl:String!) { func setAdTagUrl(_ adTagUrl:String!) {
_adTagUrl = adTagUrl _adTagUrl = adTagUrl
} }
func getContentPlayhead() -> IMAAVPlayerContentPlayhead? { func getContentPlayhead() -> IMAAVPlayerContentPlayhead? {
return _contentPlayhead return _contentPlayhead
} }
func setAdPlaying(_ adPlaying:Bool) { func setAdPlaying(_ adPlaying:Bool) {
_adPlaying = adPlaying _adPlaying = adPlaying
} }