这是我的问题。 另请注意,我不知道AdWhirl,但选择不使用它,因为我更愿意控制我的广告发生的事情。
基本上我有iAd和AdMob。我一开始就使用iAds,如果广告没有显示任何内容,我会初始化AdMob并开始显示它。然后,当iAds终于显示某些内容时,我会隐藏Admob广告并销毁视图并再次显示iAd。
这似乎适用于1次迭代,意思是:
问题是..随着时间的推移如果我让应用程序继续运行并且iAd无法加载广告几次(意味着我做了一些切换导致创建Admob视图),发布的Admob视图对象未被释放即使它不应该继续接收新广告。
以下是我从iAds收到代码3时运行的代码(意思是:操作无法完成。广告资源不可用)
-(void) smartInitialize:(UIViewController*) theVC
{
NSLog(@"AMOB :: smartInitialize");
if(!initialized)
{
NSLog(@"AMOB :: PRE initialization");
CGRect appFrame = [UIScreen mainScreen].applicationFrame;
UIView * theView = [[UIView alloc] initWithFrame:appFrame];
theView.autoresizingMask = UIViewAutoresizingFlexibleHeight;
theViewController = theVC;
//[theViewController retain];
self.view = theView;
[theView release];
adMobAd = nil;
adMobAd = [self requestNewAdmobView];
if(adMobAd != nil)
{
NSLog(@"AMOB :: adding ADMOBVIEW TO VIEW CONTROLLER!");
[theVC.view addSubview:adMobAd];
[adMobAd release];
}
initialized = YES;
}
else
{
NSLog(@"AMOB :: POST initialization");
if(adMobAd!=nil)
{
NSLog(@"AMOB :: adMobView is present, doing nothing...");
}
else
{
NSLog(@"AMOB :: reinitializing..");
[self reinitializeAdmob];
}
}
}
这是[self requestNewAdmobView]功能:
- (GADBannerView*) requestNewAdmobView
{
NSLog(@"AMOB :: requestNewAdmobView");
CGRect adFrame = CGRectZero;
NSString * appID = nil;
adMobAd = nil;
if(DEVICE_IPAD)
{
adFrame.size = GAD_SIZE_728x90;
appID = @"id1";
}
else
{
adFrame.size = GAD_SIZE_320x50;
appID = @"id2";
}
GADBannerView * tmp = nil;
tmp = [[GADBannerView alloc] initWithFrame:adFrame];
if(tmp != nil)
{
NSLog(@"AMOB :: adMobAD != nil , commencing with other stuff!");
tmp.adUnitID = appID;
tmp.rootViewController = gD.viewController;
tmp.delegate = self;
[tmp loadRequest:[GADRequest request]];
[tmp setHidden:NO];
}
else
{
NSLog(@"AMOB :: adMobAD == nil , THIS IS BAD..");
}
return tmp;
}
这是[self reinitializeAdmob]功能:
-(void) reinitializeAdmob
{
NSLog(@"AMOB :: reinitializeAdmob");
if(theViewController != nil)
{
[self shutdownAdmob];
adMobAd = nil;
adMobAd = [self requestNewAdmobView];
if(adMobAd!=nil)
{
[theViewController.view addSubview:adMobAd];
}
}
}
最后是[self shutdownAdmob]
-(void) shutdownAdmob
{
NSLog(@"AMOB :: shutdownAdmob");
if(adMobAd!=nil)
{
NSLog(@"AMOB :: adMobAd != nil, removing from superview and nilling...");
adMobAd.delegate = nil;
[adMobAd removeFromSuperview];
//[adMobAd release];
adMobAd = nil;
}
else
{
NSLog(@"AMOB :: adMobAd == nil");
}
}
根据我的理解,我正在正确清理名为AdMobView的GADBannerView,因为: