我正在尝试将GreyStripe(不受支持)与自定义事件的admob中介集成,我也阅读了以下指南: https://developers.google.com/mobile-ads-sdk/docs/ios/mediation/#customevents
但是对于初学者来说仍然很难理解,是否有人可以提供示例代码或一些教程。提前谢谢。
答案 0 :(得分:3)
该实现与网络有关,但这里有一个完整的示例,说明如果不支持自定义事件,您将如何集成AdMob网络。
在中介展示位置内创建自定义事件:
你的实现看起来像这样:
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
答案 1 :(得分: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]]];
}