1

我一直在谷歌上试图弄清楚如何在 adMob SDK 中打开中介!!!在自己的页面(https://developers.google.com/mobile-ads-sdk/docs/admob/mediation#ios)上,他们有一个分步指南,但也许我很愚蠢或者缺少什么。该指南指出:

将您的中介 ID(而不是 AdMob 网站 ID)指定为 GADBannerView 的 adUnitID。您可以在您创建的中介展示位置的设置页面上找到您的中介 ID

这应该在 GADBannerView.h 中,如果是的话……在哪里?

//  GADBannerView.h
//  Google AdMob Ads SDK
//
//  Copyright 2011 Google Inc. All rights reserved.
//

#import <UIKit/UIKit.h>
#import "GADAdSize.h"
#import "GADRequest.h"
#import "GADRequestError.h"
#import "GADBannerViewDelegate.h"

// The view that displays banner ads.  A minimum implementation to get an ad
// from within a UIViewController class is:
//
//   // Create and setup the ad view, specifying the size and origin at {0, 0}.
//   GADBannerView *adView =
//       [[GADBannerView alloc] initWithAdSize:kGADAdSizeBanner];
//   adView.rootViewController = self;
//   adView.adUnitID = @"ID created when registering my app";
//
//   // Place the ad view onto the screen.
//   [self.view addSubview:adView];
//   [adView release];
//
//   // Request an ad without any additional targeting information.
//   [adView loadRequest:nil];
//
@interface GADBannerView : UIView

#pragma mark Initialization

// Initializes a GADBannerView and sets it to the specified size, and specifies
// its placement within its superview bounds. If |size| is invalid, an
// instance of GADBannerView is not created and nil is returned instead.
- (id)initWithAdSize:(GADAdSize)size origin:(CGPoint)origin;

// Initializes a GADBannerView and sets it to the specified size, and specifies
// its placement at the top left of its superview. If |size| is invalid, an
// instance of GADBannerView is not created and nil is returned instead.
- (id)initWithAdSize:(GADAdSize)size;

#pragma mark Pre-Request

// Required value created in the AdSense website.  Create a new ad unit for
// every unique placement of an ad in your application.  Set this to the ID
// assigned for this placement.  Ad units are important for targeting and stats.
// Example values for different request types:
//     AdMob: a0123456789ABCD
//       DFP: /0123/ca-pub-0123456789012345/my-ad-identifier
//   AdSense: ca-mb-app-pub-0123456789012345/my-ad-identifier
// Mediation: AB123456789ABCDE
@property (nonatomic, copy) NSString *adUnitID;

// Required reference to the current root view controller.  For example the root
// view controller in tab-based application would be the UITabViewController.
@property (nonatomic, assign) UIViewController *rootViewController;

// Required to set this banner view to a proper size. Never create your own
// GADAdSize directly. Use one of the predefined standard ad sizes
// (such as kGADAdSizeBanner), or create one using the GADAdSizeFromCGSize
// method. If not using mediation, then changing the adSize after an ad has
// been shown will cause a new request (for an ad of the new size) to be sent.
// If using mediation, then a new request may not be sent.
@property (nonatomic) GADAdSize adSize;

// Optional delegate object that receives state change notifications from this
// GADBannerView.  Typically this is a UIViewController, however, if you are
// unfamiliar with the delegate pattern it is recommended you subclass this
// GADBannerView and make it the delegate.  That avoids any chance of your
// application crashing if you forget to nil out the delegate.  For example:
//
//   @interface MyAdView : GADBannerView <GADBannerViewDelegate>
//   @end
//
//   @implementation MyAdView
//   - (id)initWithFrame:(CGRect)frame {
//     if ((self = [super initWithFrame:frame])) {
//       self.delegate = self;
//     }
//     return self;
//   }
//
//   - (void)dealloc {
//     self.delegate = nil;
//     [super dealloc];
//   }
//
//   @end
//
@property (nonatomic, assign) NSObject<GADBannerViewDelegate> *delegate;

#pragma mark Making an Ad Request

// Makes an ad request.  Additional targeting options can be supplied with a
// request object.  Refresh the ad by calling this method again.
- (void)loadRequest:(GADRequest *)request;

#pragma mark Ad Request

// YES, if the currently displayed ad (or most recent failure) was a result of
// auto refreshing as specified on server.  This will be set to NO after each
// loadRequest: method.
@property (nonatomic, readonly) BOOL hasAutoRefreshed;

#pragma mark Mediation

// Gets the underlying ad view of the mediated ad network.
// You may use this to find out the actual size of the ad and adjust
// GADBannerView to fit the underlying ad view.
@property (nonatomic, readonly) UIView *mediatedAdView;

@end

如果没有,是否应该有一个 .m 文件?

请帮忙...我快疯了!

4

1 回答 1

2

不,它应该是您提出请求的地方。在视图控制器中,它将显示广告。我的工作代码:

    GADAdSize adSize;
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)
    {
        adSize = kGADAdSizeBanner;
    }else {
        adSize = kGADAdSizeLeaderboard;
    }
    CGPoint origin = CGPointMake(0.0,
                                 self.view.frame.size.height + 20 - 50 -
                                 CGSizeFromGADAdSize(adSize).height);
    bannerView = [[GADBannerView alloc] initWithAdSize:adSize origin:origin];
    // Specify the ad's "unit identifier." This is your AdMob Publisher ID.
    bannerView.adUnitID = @"39ca7331d2c4436a";

    bannerView.rootViewController = self;
    bannerView.delegate = self;

    GADRequest *request = [GADRequest request];

    [bannerView loadRequest:request];

您应该替换39ca7331d2c4436a为您的Mediation ID.

于 2013-01-12T10:38:04.760 回答