【问题标题】:Implementations on AdMob (iOS)AdMob (iOS) 上的实施
【发布时间】:2011-12-15 20:46:18
【问题描述】:

怎么样,伙计们? 所以今天这是一个非常荒谬的问题,但我无法让它按照我想要的方式工作。 我正在实施 AdMob,但我想了解更多信息。

他们在GoogleCodes/AdMob 上给出了说明 但我不能让它给我我想要的日志。

这是在.h

#import <UIKit/UIKit.h>
#import "GADBannerView.h"
#import "GADBannerViewDelegate.h"

@interface AppForAllTestsViewController : UIViewController<GADBannerViewDelegate>

这是在.m上

-(void)adViewDidReceiveAd:(GADBannerView *)bannerView{
    NSLog(@"RECEIVED");

    [UIView beginAnimations:@"BannerSlide" context:nil];
    bannerView.frame = CGRectMake(0.0, self.view.frame.size.height - bannerView.frame.size.height, 
                                   bannerView.frame.size.width, 
                                   bannerView.frame.size.height);
    [UIView commitAnimations];
}

-(void)adView:(GADBannerView *)view didFailToReceiveAdWithError:(GADRequestError *)error{
    NSLog(@"FAILURE RECEIVING AD: %@", [error localizedDescription]);
}


-(void)adMobProcess{
    adMobBanner = [[GADBannerView alloc]initWithFrame:CGRectMake(0.0, 
                                                                 self.view.frame.size.height-GAD_SIZE_320x50.height, 
                                                                 GAD_SIZE_320x50.width, 
                                                                 GAD_SIZE_320x50.height)];

    adMobBanner.adUnitID = my_id;
    adMobBanner.rootViewController = self;
    [self.view addSubview:adMobBanner];
    [adMobBanner loadRequest:[GADRequest request]];

}

-(void)awakeFromNib{
    NSLog(@"GOOD MORNING");
    [adMobBanner setDelegate:self];
}

- (void)viewDidLoad{
    [self adMobProcess];
    [super viewDidLoad];
}

您可以看到我将代理设置为“self”,但没有任何反应,没有任何更改,请任何人帮助我吗? (:

【问题讨论】:

  • 你能更新你的代码吗?不太确定!

标签: iphone ios admob ads


【解决方案1】:

AdMob iOS documentation 声明:

请记住在发出广告请求之前使用 setDelegate: 设置委托。

因为您在 awakeFromNib 中设置了委托,所以您要么在初始化 adMobBanner(NPE?)之前设置委托,要么在 adRequest 之后设置它。您应该在调用 loadRequest 之前在 adMobProcess 中设置委托。

【讨论】:

    【解决方案2】:

    下载 Google Admob 库https://developers.google.com/mobile-ads-sdk/download#downloadios

    除了 Add-ons 和 readme.txt 文件外,将所有文件拖到你的项目中

    构建设置 -> 搜索路径 -> 库搜索路径和标题搜索路径将 Google Admob 文件链接添加为 RECURSIVE $(SRCROOT)/Folder_Name Folder_Name 指定库放置的位置

    不要对 iPhone 和 iPad 使用 self.view.frame.size.height 这会导致横幅高度不同...

    使用 [[UIScreen mainScreen] bounds].size.height 这个会自动识别 iPhone 和 iPad 显示 Screen Bounds

    调整高度将横幅放置在正确的位置

    adViewDidReceiveAd 它是一个委托方法,所以在 .h 文件中你必须调用委托方法

    <GADBannerViewDelegate>
    
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
        {
    
            bannerView_ = [[GADBannerView alloc]
                           initWithFrame:CGRectMake(0.0,
                                              [[UIScreen mainScreen] bounds].size.height - 150,
                                              GAD_SIZE_728x90.width + 50,
                                              GAD_SIZE_728x90.height)];
    
        }
    
        else if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
        {
    
            bannerView_ = [[GADBannerView alloc]
                       initWithFrame:CGRectMake(0.0,
                                           [[UIScreen mainScreen] bounds].size.height - 113,
                                            GAD_SIZE_320x50.width,
                                            GAD_SIZE_320x50.height)];
    
        }
    
    
        // Specify the ad unit ID.
    
        bannerView_.adUnitID = @"****************";
    
        [bannerView_ setDelegate:self];
    
        bannerView_.rootViewController = self;
    
        [bannerView_ loadRequest:[GADRequest request]];
    }
    
    - (void)adViewDidReceiveAd:(GADBannerView *)view
    
    {
    
        [self.view addSubview:bannerView_];
    
    }
    

    【讨论】:

      【解决方案3】:

      我发现我必须在初始化横幅视图时设置框架才能使用委托。

      // Delegate methods NOT CALLED
      self.bannerView = [[DFPBannerView alloc] init];
      
      // Delegate methods ARE CALLED
      self.bannerView = [[DFPBannerView alloc] initWithFrame:CGRectMake(0, 0, 1, 1)];
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2021-09-21
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-08-28
        • 1970-01-01
        相关资源
        最近更新 更多