カスタムイベントを使用してGreyStripe(サポートされていない)をadmobメディエーションに統合しようとしてい ます。 #customevents
しかし、初心者にとってはまだ理解するのが難しいです.誰でもサンプルコードやチュートリアルを提供できますか. 前もって感謝します。
カスタムイベントを使用してGreyStripe(サポートされていない)をadmobメディエーションに統合しようとしてい ます。 #customevents
しかし、初心者にとってはまだ理解するのが難しいです.誰でもサンプルコードやチュートリアルを提供できますか. 前もって感謝します。
実装は一種のネットワーク依存ですが、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
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]]];
}