0

I've tried multiple tutorials and tried code in multiple places but can't get google admob to do anything. I get no errors, project builds and runs in simulator. No ads load and no message in debugger. Basically nothing is happening.

I've added the following in my appDelegate

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

and under didFinishLaunchingWithOptions:(NSDictionary *)launchOptions I've put

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

in my viewcontroller.h I've also added

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

added

@interface BT_viewController : UIViewController <GADBannerViewDelegate,

and

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

and

@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

then in my view controller.m ive added

- (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);
}

and then under -(void)viewDidLoad I've added

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]];

Pretty sure i got it all covered but absolutely nothing is working. No errors, no degub, zip...

Please Help!

4

1 に答える 1

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]];
于 2016-12-28T22:08:57.217 に答える