为什么我的 iAd 横幅没有显示?

发布于 2024-12-13 12:34:37 字数 777 浏览 0 评论 0原文

- (void)viewDidLoad
{

    adView = [[ADBannerView alloc] initWithFrame:CGRectZero];
    adView.requiredContentSizeIdentifiers = [NSSet setWithObject:ADBannerContentSizeIdentifierPortrait];
    adView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierPortrait;
    CGRect adFrame = adView.frame;
    adFrame.origin.y = self.view.frame.size.height-adView.frame.size.height;
    adView.frame = adFrame;
    [self.view addSubview:adView];

}


- (void)bannerViewDidLoadAd:(ADBannerView *)banner
{
    if (!self.bannerIsVisible)
    {
        self.bannerIsVisible = YES;
    }
}

- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error
{
    if (self.bannerIsVisible)
    {

        self.bannerIsVisible = NO;
    }
- (void)viewDidLoad
{

    adView = [[ADBannerView alloc] initWithFrame:CGRectZero];
    adView.requiredContentSizeIdentifiers = [NSSet setWithObject:ADBannerContentSizeIdentifierPortrait];
    adView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierPortrait;
    CGRect adFrame = adView.frame;
    adFrame.origin.y = self.view.frame.size.height-adView.frame.size.height;
    adView.frame = adFrame;
    [self.view addSubview:adView];

}


- (void)bannerViewDidLoadAd:(ADBannerView *)banner
{
    if (!self.bannerIsVisible)
    {
        self.bannerIsVisible = YES;
    }
}

- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error
{
    if (self.bannerIsVisible)
    {

        self.bannerIsVisible = NO;
    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

情仇皆在手 2024-12-20 12:34:37

有四件事。首先,您应该在 viewDidLoad 方法中将横幅放置在屏幕之外,因为它在您首次启动时只会显示一个空框架,并且很可能因此而被拒绝。

其次,您错误地设置了横幅视图。我认为框架仍然是CGZero。第三,您没有设置bannerView的委托。尝试以下操作:

-(void)viewDidLoad{
    CGRect frame=CGRectZero;
    frame.size = [ADBannerView sizeFromBannerContentSizeIdentifier:ADBannerContentSizeIdentifierPortrait];
    // Place frame at the bottom edge of the screen out of sight
    frame.origin = CGPointMake(0.0, CGRectGetMaxY(self.view.bounds));

    // Now to create and configure the banner view
    ADBannerView *adView = [[ADBannerView alloc] initWithFrame:frame];
    adView.requiredContentSizeIdentifiers = [NSSet setWithObject:ADBannerContentSizeIdentifierPortrait];
    // Set the delegate to self, so that we are notified of ad responses
    adView.delegate = self;
    [self.view addSubview: adView];
}

第四,在您的bannerViewDidLoadAd:方法中,您没有将横幅广告动画到位。试试这个:

- (void)bannerViewDidLoadAd:(ADBannerView *)banner
{
    // Get a brand new frame
    CGRect newFrame=CGRectZero;
    CGPoint frameOrigin=CGPointZero;
    // Set the origin
    frameOrigin=CGPointMake(0.0, CGRectGetMaxY(self.view.bounds));
    newFrame.origin=frameOrigin;

    // Set the size
    newFrame.size=[ADBannerView sizeFromBannerContentSizeIdentifier:ADBannerContentSizeIdentifierPortrait];

    CGFloat bannerHeight = newFrame.size.height;
    CGFloat bannerOffset=0.0;

    // Determine where the new frame should be
    if (!self.bannerIsVisible)
    {   
        // It should be visible, raise it up
        bannerOffset=-bannerHeight;
    }

    CGRect offSetRect=CGRectOffset(newFrame,0.0f,bannerOffset);
        [UIView animateWithDuration:0.2
                         animations:^{banner.view.frame=offSetRect}
                         completion:^(BOOL finished){
                             if (bannerOffSet<0){
                               self.bannerIsVisible=YES;
                             }else{
                               self.bannerIsVisible=NO;
                             }
                         }
        ]; 

}

当然,如果横幅应该位于屏幕顶部,您可能可以弄清楚需要如何修改,但这会让您朝着正确的方向前进。

祝你好运

There are a four things. First, you should be positioning the banner off screen in your viewDidLoad method because it will just show an empty frame when you first launch and will more than likely get rejected because of it.

Secondly, you are setting up your banner view incorrectly. I think the frame is still CGZero. Thirdly you are not setting the bannerView's delegate. Try the following:

-(void)viewDidLoad{
    CGRect frame=CGRectZero;
    frame.size = [ADBannerView sizeFromBannerContentSizeIdentifier:ADBannerContentSizeIdentifierPortrait];
    // Place frame at the bottom edge of the screen out of sight
    frame.origin = CGPointMake(0.0, CGRectGetMaxY(self.view.bounds));

    // Now to create and configure the banner view
    ADBannerView *adView = [[ADBannerView alloc] initWithFrame:frame];
    adView.requiredContentSizeIdentifiers = [NSSet setWithObject:ADBannerContentSizeIdentifierPortrait];
    // Set the delegate to self, so that we are notified of ad responses
    adView.delegate = self;
    [self.view addSubview: adView];
}

Fourth, in your bannerViewDidLoadAd: method you are not animating the banner ad into place. Try this:

- (void)bannerViewDidLoadAd:(ADBannerView *)banner
{
    // Get a brand new frame
    CGRect newFrame=CGRectZero;
    CGPoint frameOrigin=CGPointZero;
    // Set the origin
    frameOrigin=CGPointMake(0.0, CGRectGetMaxY(self.view.bounds));
    newFrame.origin=frameOrigin;

    // Set the size
    newFrame.size=[ADBannerView sizeFromBannerContentSizeIdentifier:ADBannerContentSizeIdentifierPortrait];

    CGFloat bannerHeight = newFrame.size.height;
    CGFloat bannerOffset=0.0;

    // Determine where the new frame should be
    if (!self.bannerIsVisible)
    {   
        // It should be visible, raise it up
        bannerOffset=-bannerHeight;
    }

    CGRect offSetRect=CGRectOffset(newFrame,0.0f,bannerOffset);
        [UIView animateWithDuration:0.2
                         animations:^{banner.view.frame=offSetRect}
                         completion:^(BOOL finished){
                             if (bannerOffSet<0){
                               self.bannerIsVisible=YES;
                             }else{
                               self.bannerIsVisible=NO;
                             }
                         }
        ]; 

}

of course if the banner is supposed to be positioned at the top of the screen, you can probably figure out how things need to be modified, but this gets you in going in the right direction.

Good luck

夕嗳→ 2024-12-20 12:34:37

阅读您的问题后不确定,但请注意 Apple 模拟 iAds 不可用。有时您需要多次尝试才能看到示例广告。

Not sure by reading your question, but do be aware that Apple simulates iAds not being available. Sometimes you need to try multiple times before the sample ad comes through.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文