larsacus / LARSAdController

Lightweight ad mediation for iOS to properly manage multiple ad networks dynamically including iAd and Google ads.
http://theonlylars.com/blog/2013/01/10/stupid-easy-ads-with-larsadcontroller-3-dot-0/
MIT License
269 stars 60 forks source link

Mixing LARSAdController with ARC #6

Closed ghost closed 12 years ago

ghost commented 12 years ago

Hi Larsacus!

First of all, thanks for this great job!!

I would like to ask you about the behavior when the app is going to the background, because when the app is in background release all the views, and when you put again to the app, the app crash, because some banner is waiting a view who is released by the system. I tried to put a nil the delegates whe you are going to background in the app delegate, but this is not a good solution, because the banner is blank for some moments.

Thanks in advance!!

larsacus commented 12 years ago

Did you convert the code to ARC? Or did you just use the -f-no-objc-arc flag?

ghost commented 12 years ago

I just used -fno-objc-arc, but is like the object is not release at the same time of the container view.

larsacus commented 12 years ago

The ad controller actually retains all views and ad instances, so there should be no releasing of the views unless the ad controller gets deallocated, which should never happen since it is a singleton.

Are you seeing a specific crash in a crash report?

ghost commented 12 years ago

yes, at the beggining i recieved a BAD_EXC in this line of the code, (when the app come from background mode)

if(self.containerView.superview != self.parentView){ <------ HERE [self.parentView addSubview:self.containerView]; <------ HERE [self.parentView bringSubviewToFront:self.containerView]; [self.containerView bringSubviewToFront:self.iAdBannerView];

I activated NSZombie to know what was happening, and the message was something about the view was deallocated.

larsacus commented 12 years ago

It does appear this is related to the view in the actual implementation regardless of if ARC is being used or not. I'll look into if there is anything I can do on my end in order to prevent this kind of thing.

larsacus commented 12 years ago

Please see the last commit. For some reason the parentView and parentViewController properties were set to assign when they should have been set to retain in order to keep a reference to the view that it is actually in. This is why you were getting an BAD_EXC in your code since your view controller were being released, but the ad framework expected it to be there and was still referencing it like it was still there. This should help by having the ad container keep a reference to your view and view controller so that they will not be released out from under the ad controller before it expects it.

ghost commented 12 years ago

Thanks!!