1

我正在尝试将 GreyStripe(不受支持)集成到带有自定义事件的 admob 中介中,我还阅读了以下指南: https ://developers.google.com/mobile-ads-sdk/docs/ios/mediation/ #customevents

但是对于初学者来说仍然很难理解,有没有人可以提供示例代码或一些教程。提前致谢。

4

2 回答 2

3

实施在某种程度上取决于网络,但这里有一个完整示例,说明如果尚未支持,您将如何通过自定义事件集成 AdMob 网络。

在您的中介展示位置中创建自定义事件:

  • 标签 - blahblahblah(可以是任何字符串)
  • 类名 - CustomAd(您的类的名称。在本例中为 CustomAd)
  • 参数 - a1401234567890(在 AdMob 的情况下,您只需要您的发布商 ID。您可能希望在此处使用您自己的发布商 ID,这只是一个示例)

你的实现看起来像这样:

CustomAd.h

#import "GADCustomEventBanner.h"
#import "GADCustomEventBannerDelegate.h"
#import "GADBannerView.h"
#import "GADBannerViewDelegate.h"

@interface CustomAd : NSObject <GADCustomEventBanner, GADBannerViewDelegate> {
  GADBannerView *bannerView_;
}

@end

CustomAd.m

#import CustomAd.h

@implementation CustomAd

// Will be set by the AdMob SDK.
@synthesize delegate;

- (void)dealloc {
  bannerView_.delegate = nil;
  [bannerView_ release];
  [super dealloc];
}

#pragma mark -
#pragma mark GADCustomEventBanner

- (void)requestBannerAd:(GADAdSize)adSize
              parameter:(NSString *)serverParameter
                  label:(NSString *)serverLabel
                request:(GADCustomEventRequest *)customEventRequest  {
  // Create the bannerView with the appropriate size.
  bannerView_ = [[GADBannerView alloc] initWithAdSize: adSize];

  // Set the delegate to listen for callbacks.
  [bannerView_ setDelegate:self];

  // Set the publisher ID for the banner.  This comes from server parameter
  // you provide when creating the custom event in mediation.
  bannerView_.adUnitID = serverParameter;

  // Let the bannerView know which UIViewController to restore after returning
  // from and ad click.  The UIViewController is available from
  // GADCustomEventBannerDelegate.
  bannerView_.rootViewController = [self.delegate viewControllerForPresentingModalView];

  // Create an ad request using custom targeting options from the custom event
  // request.
  GADRequest *request = [GADRequest request];
  [request setAdditionalParameters:[customEventRequest additionalParameters]];
  [request setBirthday:[customEventRequest userBirthday]];
  [request setGender:[customEventRequest userGender]];
  [request setTesting:[customEventRequest isTesting]];
  if ([customEventRequest userHasLocation]) {
    [request setLocationWithLatitude:[customEventRequest userLatitude] 
                           longitude:[customEventRequest userLongitude]
                            accuracy:[customEventRequest userLocationAccuracyInMeters]];
  }
  [bannerView_ loadRequest:request];
}

#pragma mark -
#pragma mark GADBannerView Callbacks

- (void)adViewDidReceiveAd:(GADBannerView *)adView {
  [self.delegate customEventBanner:self didReceiveAd:adView];
}

- (void)adView:(GADBannerView *)view
    didFailToReceiveAdWithError:(NSError *)error {
  [self.delegate customEventBanner:self didFailAd:error];
}

- (void)adViewWillPresentScreen:(GADBannerView *)adView {
  [self.delegate customEventBanner:self clickDidOccurInAd:adView];
  [self.delegate customEventBannerWillPresentModal:self];
}

- (void)adViewWillDismissScreen:(GADBannerView *)adView {
  [self.delegate customEventBannerWillDismissModal:self];
}

- (void)adViewDidDismissScreen:(GADBannerView *)adView {
  [self.delegate customEventBannerDidDismissModal:self];
}

- (void)adViewWillLeaveApplication:(GADBannerView *)adView {
  [self.delegate customEventBannerWillLeaveApplication:self];
}

@end
于 2012-05-31T21:42:04.753 回答
0

我正在尝试为 Nexage 编写自定义事件,它不会删除旧视图并将新广告放在屏幕上。

static BOOL hasInitializedOnce;

@implementation NexageAdMobCustomEventBanner

@synthesize delegate, bannerView_;

- (void)requestBannerAd:(GADAdSize)adSize
          parameter:(NSString *)serverParameter
              label:(NSString *)serverLabel
            request:(GADCustomEventRequest *)request
{
    if (!hasInitializedOnce)
    {
        // Initialize Manager
        [[NexageManager sharedInstance] startUpWithDelegate:self
                                           mediationUrl:@"http://xxxxx.nexage.com"
                                                    dcn:@"xxxxxx"
                                             attributes:nil
                                               features:nil];
    [NexageManager sharedInstance].currentViewController = [self.delegate viewControllerForPresentingModalView];

    // Create banner and immediately get ad
    bannerView_ = [[NexageAdView alloc] initWithPosition:serverParameter frame:CGRectMake(0, 0, 320, 50)];
    [bannerView_ setIntervalTo:10];

    // Set it so that it won't call our Manager again
    hasInitializedOnce = YES;
    NSLog(@"Creating the Banner view for Mediation callback");
}
else
{
//        [bannerView_ rollover];
    NSLog(@"Rolling over the Banner view for Mediation callback");
}


}

- (void)adReceived:(UIView *)ad position:(NSString *)pos
{
    NSLog(@"Nexage Banner received!");
    [self.delegate customEventBanner:self didReceiveAd:ad];
}

- (void)adDidHide:(UIView *)adView
{
    NSLog(@"Called here...");
}

- (void)didFailToReceiveAd:(NSString *)position
{
    [self.delegate customEventBanner:self didFailAd:[NSError errorWithDomain:@"Nexage" code:200 userInfo:[NSDictionary dictionaryWithObjectsAndKeys:@"Not able to get a new Ad", NSLocalizedDescriptionKey, nil]]];
}
于 2013-03-19T06:59:52.760 回答