gpt4 book ai didi

iOS Interstitial iAd 不关闭

转载 作者:可可西里 更新时间:2023-11-01 05:12:41 25 4
gpt4 key购买 nike

我的 iAd 集成无法正常工作。我尝试实现全屏广告。广告出现了,但当我按下“X”按钮关闭时,它没有关闭。

也许您可以在我的代码中找到问题?我不知道要更改什么并且已投入大量时间来解决问题但没有成功。

更新

它适用于 [interstitial presentFromViewController:self]; 但不适用于 [interstitial presentInView:self.view]; 问题是 presentFromViewController 在 iOS 7 中已被弃用...所以我该如何更改它?


- (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");
}

提前谢谢你:)

最佳答案

对我来说,这个问题的最佳解决方案是将 [interstitial presentInView:self.view]; 替换为 [_interstitialAd presentInView:_adPlaceholderView]; 其中 _adPlaceholderView 是与 self.view 具有相同边界的 View ,并在显示广告之前添加。不要忘记在广告结束后删除此 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;
}

希望对你也有帮助。

关于iOS Interstitial iAd 不关闭,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22464474/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com