开发者

Why does iAd still load data after it has been removed from it's superview, and can this be stopped?

开发者 https://www.devze.com 2023-03-04 20:47 出处:网络
I have a small app with iAds, and allow people to pay to upgrade. The iAd is setup in the application\'s NIB.I check the purchase status in the viewDidLoad method of the main UIViewController, and ca

I have a small app with iAds, and allow people to pay to upgrade.

The iAd is setup in the application's NIB. I check the purchase status in the viewDidLoad method of the main UIViewController, and call the following methods on the ADBannerView outlet member:

[adBanner removeFromSuperview];
adBanner = nil;

Unfortunately if I watch the device's data usage, some data is still downloaded for the Ad.

Is there any way to properly kill the iAd so it doesn't load any data?

I know I could create the iAd view programatically and then add it only if the user has not purchased the product, but my product is working nicely from the NIB and I'd rather not change it for开发者_开发问答 this reason.

UPDATE:

In my .h file I have:

IBOutlet ADBannerView* adBanner;

In the .m file in - (void)viewDidLoad method I have:

if (purchased) {
    [adBanner removeFromSuperview];
    adBanner.delegate = nil;
    adBanner = nil;
}

I would hope this would be enough to remove the iAd before it gets a chance to download any data.

Alas, this isn't enough to prevent the view from downloading data. I suspect there is a delay in it being fully dealloc'd at that time – but I don't know how to do this, short of calling dealloc itself.

Does anyone know of a better/correct way to completely destroy an object loaded via the XIB and assigned to an IBOutlet?


I suspect you don't completely release the ad banner.

Did you autorelease the adBanner when creating it? If you didn't, the code you are showing here doesn't properly release the banner.

Most likely, you didn't autorelease it and it's retained. What you need to do is:

[adBanner release]; 

instead of

adBanner = nil;

which is by the way useless since it only sets the pointer adBanner to nil but doesn't release the object at all.


I think you'll have to use a second nib, without the iAd banner. The nib loading process will instantiate all elements of the nib before passing control back to your objects. That's why you can't stop the iAd from trying to load an ad.

First, duplicate the current nib, and just delete the iAd banner view. Then override the view controller's initWithNibName:bundle: method to check for paid status. If paid, change the nib name to the non iAd nib, and call the superclass's method with the other nib.


You could set the adBanner.delegate = nil also, to stop the adBanner from communicating with it's delegate.


@mr-berna is right in that you need to conditionally load the iAd view. You can either do as he suggests and use a second nib or create the iAd view programmatically.

0

精彩评论

暂无评论...
验证码 换一张
取 消