2016-12-28 66 views
0

我已经尝试了多个教程,并尝试了多个地方的代码,但无法让Google admob执行任何操作。我没有得到任何错误,项目构建并在模拟器中运行。调试器中没有广告加载和消息。 基本上什么都没有发生。无法让admob在ios8应用程序上工作

我已在我的appDelegate以下

#import <GoogleMobileAds/GoogleMobileAds.h> 
#import <GoogleMobileAds/GADBannerView.h> 
#import <GoogleMobileAds/GADBannerViewDelegate.h> 
#import "Firebase.h" 

didFinishLaunchingWithOptions:(NSDictionary *)launchOptions我已经把

[FIRApp configure]; 
[GADMobileAds configureWithApplicationID:@"ca-app-pub-5601547953982889~9365662253"]; 

在我viewcontroller.h我还添加了

#import <GoogleMobileAds/GoogleMobileAds.h> 
#import <GoogleMobileAds/GADBannerView.h> 
#import <GoogleMobileAds/GADBannerViewDelegate.h> 
#import "Firebase.h" 

添加

@interface BT_viewController : UIViewController <GADBannerViewDelegate, 

@property (nonatomic, weak) IBOutlet GADBannerView *bannerView; 

@protocol GADBannerViewDelegate <NSObject> 
@optional 
- (void)adViewDidReceiveAd:(GADBannerView *)bannerView; 
- (void)adView:(GADBannerView *)bannerView 
didFailToReceiveAdWithError:(GADRequestError *)error; 
- (void)adViewWillPresentScreen:(GADBannerView *)bannerView; 
- (void)adViewDidDismissScreen:(GADBannerView *)bannerView; 
- (void)adViewWillDismissScreen:(GADBannerView *)bannerView; 
- (void)adViewWillLeaveApplication:(GADBannerView *)bannerView; 

@end 
在我看来Controller.m或者香港专业教育学院

然后加入

- (void)adViewDidReceiveAd:(GADBannerView *)bannerView { 
bannerView.hidden = NO; 
    [BT_debugger showIt:self theMessage:@"Google ad shown"]; 
} 
- (void)adView:(GADBannerView *)bannerView didFailToReceiveAdWithError: (GADRequestError *)error { 
NSLog(@"adView:didFailToReceiveAdWithError: %@", error.localizedDescription); 
} 

,然后-(void)viewDidLoad下我加

self.bannerView = [[GADBannerView alloc] 
        initWithFrame:CGRectMake(0.0, 
              self.view.frame.size.height - 
              GAD_SIZE_320x50.height, 
              GAD_SIZE_320x50.width, 
              GAD_SIZE_320x50.height)]; 
self.bannerView.delegate = self; 
self.bannerView.adUnitID = @"ca-app-pub-3940256099942544/2934735716"; 

self.bannerView.rootViewController = self; 
[self.view addSubview:self.bannerView]; 

[self.bannerView loadRequest:[GADRequest request]]; 

很确定我把它全部覆盖,但绝对没有什么工作。没有错误,没有软化剂,拉链...

请帮助!

+0

您是否自己实施了Google Ad Mob功能,而不是通过Cocoa Pod进行安装? – Mochi

+0

请分享您的古柯豆荚文件,如果您手动完成,所有库都添加了什么?还分享日志。通常日志显示消息 –

+0

我实施了自己并添加了以下框架 –

回答

0

所以我决定尝试使用可可豆荚进行安装,但仍然有相同的结果。然后我在GADbannerview文件中发现它有一个加载广告的示例代码。我试过这段代码,现在显示广告!

GADBannerView *adView = [[GADBannerView alloc] initWithAdSize:kGADAdSizeBanner]; 
adView.rootViewController = self; 
adView.adUnitID = @"ca-app-pub-3940256099942544/2934735716"; 
/// // Place the ad view onto the screen. 
[self.view addSubview:adView]; 
/// // Request an ad without any additional targeting information. 
[adView loadRequest:[GADRequest request]]; 
相关问题