我尝试了多个教程并在多个地方尝试了代码,但无法让 google admob 做任何事情。我没有收到任何错误,项目在模拟器中构建和运行。没有广告加载,调试器中也没有消息。基本上什么都没有发生。
我在 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]];
很确定我把这一切都涵盖了,但绝对没有任何效果。没有错误,没有调试,压缩...
请帮忙!