无法让adob在ios8应用程序上工作

时间:2016-12-28 04:06:39

标签: ios objective-c admob google-admob

我尝试了多个教程并尝试了多个地方的代码,但无法让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]];

很确定我把它全部覆盖但绝对没有任何效果。没有错误,没有脱毛,拉链...

请帮助!

1 个答案:

答案 0 :(得分:0)

所以我决定尝试使用Cocoa Pods安装,但仍然有相同的结果。然后我在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]];