我的iAd集成无法正常工作。我尝试实施全屏广告。广告出现但是当我按下“X”按钮关闭时,它不会关闭。
也许您可以在我的代码中找到问题?我不知道该改变什么,并且花了很多时间来解决问题而没有成功。
更新
适用于[interstitial presentFromViewController:self];
,但不适用于[interstitial presentInView:self.view];
问题是在iOS 7中不推荐使用presentFromViewController ...所以我该如何更改呢?
- (void)viewDidLoad
{
requestingAd = NO;
[self showFullScreenAd];
}
//Interstitial iAd
-(void)showFullScreenAd {
//Check if already requesting ad
if (requestingAd == NO) {
interstitial = [[ADInterstitialAd alloc] init];
interstitial.delegate = self;
self.interstitialPresentationPolicy = ADInterstitialPresentationPolicyManual;
[self requestInterstitialAdPresentation];
NSLog(@"interstitialAdREQUEST");
requestingAd = YES;
}//end if
}
-(void)interstitialAd:(ADInterstitialAd *)interstitialAd didFailWithError:(NSError *)error {
interstitial = nil;
requestingAd = NO;
NSLog(@"interstitialAd didFailWithERROR");
NSLog(@"%@", error);
}
-(void)interstitialAdDidLoad:(ADInterstitialAd *)interstitialAd {
NSLog(@"interstitialAdDidLOAD");
if (interstitialAd != nil && interstitial != nil && requestingAd == YES) {
[interstitial presentInView:self.view];
NSLog(@"interstitialAdDidPRESENT");
}//end if
}
-(void)interstitialAdDidUnload:(ADInterstitialAd *)interstitialAd {
interstitial = nil;
requestingAd = NO;
NSLog(@"interstitialAdDidUNLOAD");
}
-(void)interstitialAdActionDidFinish:(ADInterstitialAd *)interstitialAd {
interstitial = nil;
requestingAd = NO;
NSLog(@"interstitialAdDidFINISH");
}
提前谢谢你:)
答案 0 :(得分:4)
我有同样的问题。不确定你是否已经弄清楚了这一点,但实际上并不需要出现在视图中。
您需要致电[self requestInterstitialAdPresentation]
。但是......如果广告未加载,则不会在视图中显示,也不会向您提供类似于旧版iAd API的日志或警告。
我最好的建议是在加载视图之前,从您调用要加载的视图控制器的任何地方开始,这是您设置Presentation Policy的地方。我的另一个建议是在AppDelegate中调用[UIView prepareInterstitialAds]。在您申请广告之前,它可以更好地加载广告。
希望有所帮助。祝你好运。
答案 1 :(得分:4)
此问题的最佳解决方案是将[interstitial presentInView:self.view];
替换为[_interstitialAd presentInView:_adPlaceholderView];
,其中_adPlaceholderView
与self.view
具有相同的边界,并在显示广告之前添加。并且在广告结束后不要忘记删除此视图。
完成的方法如下所示:
-(void)interstitialAdDidLoad:(ADInterstitialAd *)interstitialAd
{
if ((interstitialAd != nil) && (_interstitialAd != nil) && (_requestingAd))
{
_adPlaceholderView = [[UIView alloc] initWithFrame:self.view.bounds];
[self.view addSubview:_adPlaceholderView];
[_interstitialAd presentInView:_adPlaceholderView];
}
}
-(void)interstitialAdActionDidFinish:(ADInterstitialAd *)interstitialAd
{
_interstitialAd = nil;
_requestingAd = NO;
[_adPlaceholderView removeFromSuperview];
_adPlaceholderView = nil;
}
我希望它也能帮到你。