gpt4 book ai didi

ios - 当我的应用程序首次启动时,iAd 拒绝在第一个屏幕上加载广告

转载 作者:行者123 更新时间:2023-11-29 11:22:55 25 4
gpt4 key购买 nike

当我的应用程序启动时,iAd 拒绝在第一个屏幕上加载广告。没有错误信息,什么都没有。如果我切换屏幕(转到另一个屏幕),它会开始获取广告并转换广告,即使我返回到第一个屏幕也是如此。

我正在使用 ApplicationDelegate 中的单个 iAd 实例。我试图在 viewDidAppear 中链接 iAdBanner,并在 viewWillDisappear 中取消链接。

viewDidAppear 方法:

- (void)viewDidAppear:(BOOL)animated
{
NSLog(@"view did appear");
[super viewDidAppear:animated];

ADBannerView *adBanner = SharedAdBannerView;

adBanner.requiredContentSizeIdentifiers = (&ADBannerContentSizeIdentifierPortrait != nil) ?
[NSSet setWithObjects:ADBannerContentSizeIdentifierPortrait, ADBannerContentSizeIdentifierLandscape, nil] :
[NSSet setWithObjects:ADBannerContentSizeIdentifier320x50, ADBannerContentSizeIdentifier480x32, nil];


[self.view addSubview:adBanner];
// set the delegate to self, so that we are notified of ad responses
[adBanner setDelegate:self];
isAdShown = [adBanner isBannerLoaded];
[self layoutForCurrentOrientation:animated];
}

布局方式:

- (void)layoutForCurrentOrientation:(BOOL)animated
{
//TODO: this only handles bottom-located elements


ADBannerView *adBanner = SharedAdBannerView;

CGFloat animationDuration = animated ? 0.2f : 0.0f;
// by default content consumes the entire view area
CGRect contentFrame = contentView.bounds;
CGRect owningViewFrame = [self view].bounds;
// the banner still needs to be adjusted further, but this is a reasonable starting point
// the y value will need to be adjusted by the banner height to get the final position
CGPoint bannerOrigin = CGPointMake(CGRectGetMinX(owningViewFrame), CGRectGetMaxY(owningViewFrame));
CGFloat bannerHeight = 0.0f;

// First, setup the banner's content size and adjustment based on the current orientation
if(UIInterfaceOrientationIsLandscape(self.interfaceOrientation))
adBanner.currentContentSizeIdentifier = (&ADBannerContentSizeIdentifierLandscape != nil) ? ADBannerContentSizeIdentifierLandscape : ADBannerContentSizeIdentifier480x32;
else
adBanner.currentContentSizeIdentifier = (&ADBannerContentSizeIdentifierPortrait != nil) ? ADBannerContentSizeIdentifierPortrait : ADBannerContentSizeIdentifier320x50;
bannerHeight = adBanner.bounds.size.height;

// Depending on if the banner has been loaded, we adjust the content frame and banner location
// to accomodate the ad being on or off screen.
// This layout is for an ad at the bottom of the view.
if (isAdShown)
{
NSLog(@"Banner is loaded");
contentFrame.size.height = owningViewFrame.size.height - bannerHeight;
bannerOrigin.y -= bannerHeight;
}
else
{
NSLog(@"Banner is not loaded");
bannerOrigin.y += bannerHeight;
contentFrame.size.height = owningViewFrame.size.height;
}
NSLog(@"Banner content Frame: (%f, %f), (%f, %f)", bannerOrigin.x, bannerOrigin.y, contentFrame.size.width, contentFrame.size.height);
// And finally animate the changes, running layout for the content view if required.
[UIView animateWithDuration:animationDuration
animations:^{
contentView.frame = contentFrame;
[contentView layoutIfNeeded];
adBanner.frame = CGRectMake(bannerOrigin.x, bannerOrigin.y, adBanner.frame.size.width, adBanner.frame.size.height);
}];
}

和 viewWillDisappear 方法:

-(void)viewWillDisappear:(BOOL)animated
{
NSLog(@"View will disappear");
[super viewWillDisappear:animated];
[self removeLinkToAdBanner:animated];
}
-(void)removeLinkToAdBanner:(BOOL)animated
{
ADBannerView *adBanner = SharedAdBannerView;
if ([adBanner delegate] == self) {
adBanner.delegate = nil;
[adBanner removeFromSuperview];
}
}

真正令人沮丧的是,在我升级到 xcode 4 之前,它在模拟器中工作。我升级了,突然间它停止工作了。还有其他人看到过这样的行为吗?任何想法我可以做些什么来解决它?该行为发生在 4.x(4.0 到 4.3)所有测试版本的模拟器中。

最佳答案

我遇到了同样的问题,修复在 AppDelegate 的 bannerViewDidLoadAd 方法中。您需要在那里调用您的 showBanner 方法,以便最初显示广告。

- (void)bannerViewDidLoadAd:(ADBannerView *)banner
{
[_currentController showBannerView:_bannerView animated:YES];
}

请检查新的 iAdSuite 示例代码,我将其取出。

iAdSuite Sample Code Updated 10/31/11

关于ios - 当我的应用程序首次启动时,iAd 拒绝在第一个屏幕上加载广告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5918399/

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