【问题标题】:iAd code sketchyiAd 代码粗略
【发布时间】:2010-12-30 03:59:18
【问题描述】:

我已经实现了 iAd 代码,但是无论是在模拟器上还是在我的设备上,它都喜欢在一段时间后让 iAd 消失,即使在互联网连接良好的情况下也是如此。我的实现是否有问题,或者这只是预期的?下面是代码和显示两者被调用频率的控制台。谢谢!

- (void)viewDidLoad {
    adView = [[ADBannerView alloc] initWithFrame:CGRectZero];
    adView.frame = CGRectOffset(adView.frame, 0, 435);   //orginally -50
 adView.requiredContentSizeIdentifiers = [NSSet setWithObject:ADBannerContentSizeIdentifier320x50];
 adView.currentContentSizeIdentifier = ADBannerContentSizeIdentifier320x50;
    [self.view addSubview:adView];
    adView.delegate = self;
    self.bannerIsVisible = NO;

    [super viewDidLoad];
}

- (void)bannerViewDidLoadAd:(ADBannerView *)banner {
    NSLog(@"bannerViewDidLoadAd");

 if (!self.bannerIsVisible)
    {
        [UIView beginAnimations:@"animateAdBannerOn" context:NULL];
        // banner is invisible now and moved out of the screen on 50 px
        banner.frame = CGRectOffset(banner.frame, 0, -25);  //orginally 50
        [UIView commitAnimations];
        self.bannerIsVisible = YES;
    }
}

- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error {
    NSLog(@"bannerViewRecievedError");
 if (self.bannerIsVisible)
    {
        [UIView beginAnimations:@"animateAdBannerOff" context:NULL];
        // banner is visible and we move it out of the screen, due to connection issue
        banner.frame = CGRectOffset(banner.frame, 0, 25);  //orginally -50
        [UIView commitAnimations];
        self.bannerIsVisible = NO;
    }
}

- (void)dealloc {
    NSLog(@"dealloc");
    adView.delegate=nil;
    [adView release];
    [super dealloc];
}

控制台是这样说的:

2010-12-29 20:04:17.717 app[48943:207] bannerViewRecievedError
2010-12-29 20:04:52.410 app[48943:207] bannerViewRecievedError
2010-12-29 20:05:17.168 app[48943:207] bannerViewDidLoadAd
2010-12-29 20:05:47.166 app[48943:207] bannerViewDidLoadAd
2010-12-29 20:06:16.993 app[48943:207] bannerViewRecievedError
2010-12-29 20:06:46.803 app[48943:207] bannerViewDidLoadAd
2010-12-29 20:07:17.314 app[48943:207] bannerViewDidLoadAd
2010-12-29 20:07:47.140 app[48943:207] bannerViewRecievedError
2010-12-29 20:08:19.899 app[48943:207] bannerViewRecievedError
2010-12-29 20:08:46.978 app[48943:207] bannerViewDidLoadAd
2010-12-29 20:09:17.106 app[48943:207] bannerViewRecievedError
2010-12-29 20:09:46.930 app[48943:207] bannerViewDidLoadAd
2010-12-29 20:10:17.114 app[48943:207] bannerViewDidLoadAd
2010-12-29 20:10:47.609 app[48943:207] bannerViewDidLoadAd

【问题讨论】:

标签: iphone objective-c iad


【解决方案1】:

不,这里没有问题。 Apple 每隔一段时间就会提供新的模拟广告,有时您会遇到错误以测试您的错误处理能力。该错误可能意味着“没有可用的库存”,这会使您的广告消失。来自relevant developer documentation

如果发生错误,横幅视图 调用代表的 横幅视图:didFailToReceiveAdWithError: 方法。发生这种情况时,您的 应用程序必须隐藏横幅视图。 清单 2-3 显示了一种可能的方式 实现这一点。它使用相同的 属性如清单 2-2 来跟踪 横幅是否可见。如果 横幅可见且出现错误 发生时,它会将横幅从 屏幕。

即使在将错误发送到您的 委托,横幅视图继续 尝试下载新广告。 这两个代表的组合 方法允许您显示 仅当有广告时才使用横幅 已加载。

很好的错误处理实现!

【讨论】:

【解决方案2】:

这样做是为了确保您可以正确处理 iAd 错误。它会随机给你错误以及良好的测试数据。

【讨论】:

猜你喜欢
  • 2021-09-04
  • 2014-06-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-01-28
  • 1970-01-01
相关资源
最近更新 更多