Destroying ad manager after removing player view from superview causes error

962 views
Skip to first unread message

Gal Orlanczyk

unread,
Jun 21, 2017, 4:35:38 AM6/21/17
to Interactive Media Ads SDK

Hi,

Since updating to version 3.5.2 I have been seeing the error: "Ads cannot be requested because the ad container is not attached to the view hierarchy".
For sure my view is in the view hierarchy but what I noticed is this:
when I call remove from superview before the video view controller is disappearing and destroying IMA instance the IMA SDK probably doesn't reset it's states and in the next time I request ads it fails with this error, on the first time everything works fine and it usually happens if I quit in the middle of an ad.

Thanks,
Gal

Chris Feldman (IMA SDK Team)

unread,
Jun 21, 2017, 11:48:32 AM6/21/17
to Interactive Media Ads SDK
Hi Gal,

Based on the error, it sounds like an issue with how you've implemented the SDK. If you're destroying your IMA instance then you'll have to recreate it for each subsequent ad request. The SDK will not reset itself. Please try resetting the SDK before each ad request.

If you continue to have problems, I'm going to need more information about your implementation. Are you able to reproduce this error in any of our samples? If so, please provide detailed steps for how to do so. If you're not able to reproduce the issue in our samples then I'll need you to send a zip file with a project that will allow me to reproduce the issue.

Regards,
Chris Feldman
IMA SDK Team

Gal Orlanczyk

unread,
Jun 22, 2017, 1:30:16 AM6/22/17
to Interactive Media Ads SDK
Hi Chris, 

What I am doing is destroying the ads manager and calling contentComplete(). I keep the loader instance as static so I will not have to recreate it each time.
In action what happens is the first time I use the SDK everything works as expected.
Before our video player is destroyed and it calls adsManager destroy we called removed from superview for our player view which in turn holds the ad container. 
This causes the Ima sdk to send the error I wrote even though the view exists in the view hierarchy.
When calling remove from superview on the player view after we call destroy on Ima everything works fine.
This indicates 2 things: 
1. IMA SDK iOS probably has something that keeps old state calling remove from superview on the previous run should apply anything to the second time.
2. that the Issue is not with my implementation because calling remove from superview shouldn't have any effect if it is being called before or after adsManager destroy.

Keep in mind this is also only happening in version 3.5.2 (3.4.1 worked fine).
Please try calling remove from superview on the player view in the sample app in view will disappear like this to see I receive the error:

if (adsManager != nil) {

        self.videoView.removeFromSuperview()

        adsManager!.destroy()

        adsManager = nil

}

Chris Feldman (IMA SDK Team)

unread,
Jun 22, 2017, 2:01:11 PM6/22/17
to Interactive Media Ads SDK
Hi Gal,

Can you please help me understand what your use case is for removing the superview? Based on what you've shared so far, it sounds like you're removing the adContainer and then trying to request ads. As far as I can tell, you're not re-adding the superview before making the ad request. Is that accurate? If so, then I'm not surprised that you're seeing this error. The videoView object will have to be active and added to the view in order to use to adDisplayContainer. So it sounds to me like the error you're getting is actually working as intended.

If I'm misunderstanding, could you perhaps take a screen recording so I can see exactly what's happening? If it's easier, you can also send me a zipped sample project that demonstrates the behavior.

Regards,
Chris Feldman
IMA SDK Team

Gal Orlanczyk

unread,
Jun 22, 2017, 2:14:07 PM6/22/17
to Interactive Media Ads SDK
Hi Chris,

It doesn't work as intended because I can replicate it also in the sample project easily as I showed you before.

The issue is that when videoView (that being used to initialize the adContainer) is removed from his superview before we called destroy on the adManager.
And then came back to a new adManager instance and request ad after create the container again we valid videoView I receive this error.
This should not be ok because I create a new ad container that is for sure inside the view hierarchy.
And again I will mention that this did not happen before 3.5.2 and it also happen in the sample app if you will add the line I wrote in my last post.

However you look at it, calling remove from superview before calling destroy AdManager on view will disappear should not cause this issue when creating a new instance again.

If you still don't understand what I mean after you look at the change I mentioned lets try and maybe make a voice call or something.
Because we are going in circles here...

Chris please try and do what I mentioned in the sample app. the error should not be shown this is wrong.

Chris Feldman (IMA SDK Team)

unread,
Jun 22, 2017, 3:19:45 PM6/22/17
to Interactive Media Ads SDK
Hi Gal,

Thank you for clarifying. I wasn't clear on the fact that you were adding the view back before making a new ad request. That makes more sense.

I was able to recreate the circumstances and I see the same error as you. I will bring this to the rest of our team so that we can investigate. I will let you know as soon as I have any more information.

Regards,
Chris Feldman
IMA SDK Team

Chris Feldman (IMA SDK Team)

unread,
Jul 25, 2017, 1:44:03 PM7/25/17
to Interactive Media Ads SDK
Hi Gal,

I wanted to let you know that this issue has been fixed in the latest version of the IMA SDK for iOS. For more information, you can take a look at our release history.

Regards,
Chris Feldman
IMA SDK Team

Message has been deleted
Message has been deleted

Manasa Kini

unread,
Jul 29, 2020, 11:58:12 AM7/29/20
to Interactive Media Ads SDK
Hi,

Even I'm getting the same issue as Gal..For the first time, it's working fine , but later will get an error, "Ads cannot be requested because the ad container is not attached to the view hierarchy". Also, have updated the IMA SDK with the latest version.

Thanks,
Manasa

IMA SDK

unread,
Jul 29, 2020, 5:33:30 PM7/29/20
to manas...@gmail.com, ima...@googlegroups.com
Hi,

Thank you for reaching out to us. Were you able to reproduce the behavior using our
iOS AdvancedExample sample app?

Regards,
Arnaud Casame
IMA SDK Team


ref:_00D1U1174p._5004Q22a0fo:ref
Message has been deleted

Shakti Prakash

unread,
Jul 30, 2020, 2:12:33 AM7/30/20
to Interactive Media Ads SDK

Hi Arnaud,


I am getting exact same issue in my app while requesting IMALIVEStreamRequest with asset key .

For the first time its working fine after that I am getting error like this  

Ads cannot be requested because the ad container is not attached to the view hierarchy


FYI before every ads request I am resetting adcontainer  properly here is code snippet .


-(void)requestDAIStreamWithAssestKey:(NSString *)assetKey avplayer:(AVPlayer *)player andAdContainer:(UIView *)adContainer{
   
// Create an ad display container for ad rendering.
   
self.adDisplayContainer =

   
[[IMAAdDisplayContainer alloc] initWithAdContainer:adContainer companionSlots:nil];

   
   
// Create an IMAAVPlayerVideoDisplay to give the SDK access to your video player.

   
self.IMAVideoDisplay =

   
[[IMAAVPlayerVideoDisplay alloc] initWithAVPlayer:player];

     

   
// Create a stream request. Use one of "Live stream request".

   

     

   
self.liveStreamRequest =

   
[[IMALiveStreamRequest alloc] initWithAssetKey:assetKey  

                                adDisplayContainer
:self.adDisplayContainer

                                      videoDisplay
:self.IMAVideoDisplay];

   
if (_daiDelegate == nil) {

        _daiDelegate
= [NDDAIListener new];

   
}

     
self.adsLoader.delegate = _daiDelegate;

   
[self.adsLoader requestStreamWithRequest:self.liveStreamRequest];

}





I checked iOS Advance Example unfortunately couldn't not able to reproduce the behaviour

 as IMALIVEStreamRequest is  not at all made in those sample apps .

Kindly help me out with this .


Thanks and regards 

Shakti 

IMA SDK

unread,
Jul 30, 2020, 5:42:11 AM7/30/20
to shaktipr...@gmail.com, ima...@googlegroups.com

Hi Shakti,

Thank you for your response. Just wanted to confirm if you were able to reproduce this issue using our iOS AdvancedExample sample app? If yes, kindly provide the Asset Key that you’re using and steps in order for us to reproduce the behavior on our end.

Regards,
Sherwin Diesta
IMA SDK Team



ref:_00D1U1174p._5004Q22a0fo:ref

Shakti Prakash

unread,
Jul 31, 2020, 4:34:25 AM7/31/20
to Interactive Media Ads SDK
Hi Sherwin

We are not able to reproduce the issue in iOS AdvancedExample. As seen in the sample, the  IMALiveStream component have not been used.
However, from our app end, the IMA SDK throws the error, "Ads cannot be requested because the ad container is not attached to the view hierarchy”

The details of my development setUp is given below:

• Xcode version -11.2.1
• MacOS - 10.15.6
• GoogleAds-IMA-iOS-SDK - 3.11.4

Steps to reproduce:
• For first launch of the app,  when requested for the mid roll ads, with asset key It will work fine 
next time If you play request for ads you will get error

Regards,

Manasa Kini

unread,
Jul 31, 2020, 5:32:36 AM7/31/20
to Interactive Media Ads SDK
Hi Arnaud,

iOS AdvancedExample, is not using asset key & IMALive stream..In our app, the issue is thrown from SDK whenever we request for mid roll ads and play the Live stream using asset key.

Thanks & regards,
Manasa

On Thursday, July 30, 2020 at 3:03:30 AM UTC+5:30, imasdkforumadvisor wrote:

IMA SDK

unread,
Jul 31, 2020, 7:07:56 PM7/31/20
to manas...@gmail.com, ima...@googlegroups.com
Hi Manasa and Shakti,

The issue doesn't seem to be with the IMA DAI SDK for iOS, it seem to be with your implementation. Are you also removing the player view from the superview after the ad playback?


Regards,
Arnaud Casame
IMA SDK Team


ref:_00D1U1174p._5004Q22a0fo:ref

Manasa Kini

unread,
Aug 6, 2020, 1:48:59 AM8/6/20
to Interactive Media Ads SDK

Hi Arnaud,

Greetings of the day!

Implementation wise it seems to be proper from our end. We are destroying the ads container before requesting for new ads. Please, can we get any sample where asset key is getting used for playing live request.

Regards,
Manasa

IMA SDK

unread,
Aug 6, 2020, 2:44:22 AM8/6/20
to manas...@gmail.com, ima...@googlegroups.com

Hi Manasa,

Thank you for your message. Our advanced integration sample app for SDK DAI iOS does use assetKey when requesting a live stream, please see attached screenshot. Let me know if you would be able to use this to compare against your implementation.

Regards,
Sherwin Diesta
IMA SDK Team



ref:_00D1U1174p._5004Q22a0fo:ref
img01.png

Manasa Kini

unread,
Aug 6, 2020, 3:08:47 AM8/6/20
to IMA SDK, ima...@googlegroups.com
Hi Sherwin, 

Thanks, I'll check it out. 

Regards, 
Manasa
Reply all
Reply to author
Forward
0 new messages