How to integrate GreyStripe into admob mediation with custom events

2.8k views Asked by At

I am trying to integrate GreyStripe (which is not supported by) into admob mediation with custom events , also I have read the guide at: https://developers.google.com/mobile-ads-sdk/docs/ios/mediation/#customevents

But it is still hard to understand for a beginner , does anyone can provide a sample code or some tutorial. Thanks in advance.

2

There are 2 answers

3
Eric Leichtenschlag On

The implementation is sort of network dependent, but here is a full example of how you would integrate the AdMob network via a custom event if it wasn't already supported.

Create a custom event within your Mediation placement:

  • Label - blahblahblah (can be any string)
  • Class Name - CustomAd (The name of your class. In this example it is CustomAd)
  • Parameter - a1401234567890 (In AdMob's case, you only need your publisher ID. You would want to use your own publisher ID here, this is just an example)

And your implementation would look something like this:

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
0
Muthu On

I am trying to write Custom events for Nexage and it's not removing old view and put the new ad in the screen.

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