gpt4 book ai didi

ios - 如何使用 "if"语句检测 iAd 是否已加载

转载 作者:行者123 更新时间:2023-11-29 02:57:38 24 4
gpt4 key购买 nike

我有一个代码可以根据用户何时拥有 iphone 4 或 5 以及何时购买 IAP 来创建一个按钮来删除广告。下面是它的代码:

if ((int)[[UIScreen mainScreen] bounds].size.height == 568)
{
// This is iPhone 5 screen
if (intvalue == 1) {
//No Ads
self.infoButton = [UIButton buttonWithType:UIButtonTypeInfoDark];
self.infoButton.tintColor = [UIColor whiteColor];
self.infoButton.center = CGPointMake(289, 495);
[self.view addSubview:self.infoButton];
}
else{
//Yes Ads
self.infoButton = [UIButton buttonWithType:UIButtonTypeInfoDark];
self.infoButton.tintColor = [UIColor whiteColor];
self.infoButton.center = CGPointMake(289, 451);
[self.view addSubview:self.infoButton];
}

} else {
// This is iPhone 4/4s screen
if (intvalue == 1|) {
//No Ads
self.infoButton = [UIButton buttonWithType:UIButtonTypeInfoDark];
self.infoButton.tintColor = [UIColor whiteColor];
self.infoButton.center = CGPointMake(289, 429);
[self.view addSubview:self.infoButton];
}
else{
//Yes Ads
self.infoButton = [UIButton buttonWithType:UIButtonTypeInfoDark];
self.infoButton.tintColor = [UIColor whiteColor];
self.infoButton.center = CGPointMake(289, 400);
[self.view addSubview:self.infoButton];
}
}

但是,当广告未加载时,我遇到了一个问题。该按钮在屏幕中的位置仍然高于应有的位置。如何检测广告是否未加载将按钮放置在广告被删除的位置?

最佳答案

您需要在您的类中实现 ADBannerViewDelegate 协议(protocol)。

https://developer.apple.com/library/ios/documentation/userexperience/Reference/ADBannerViewDelegate_Ref/Reference/Reference.html

加载广告时,Apple 将调用 bannerViewDidLoadAd。

当广告未加载时,Apple 将调用 bannerView:didFailToReceiveAdWithError:

因此,为了临时修复,在您的代码中,我总是绘制按钮,就好像广告没有加载一样。然后当广告确实加载时(在 bannerViewDidLoadAd 内)向下移动按钮并显示广告。

关于ios - 如何使用 "if"语句检测 iAd 是否已加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23709336/

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