Cómo escribir un complemento iAd
1: Cómo crear la biblioteca XCODE Sin mencionar que en los directorios del mismo nivel creados por otras bibliotecas publicitarias, la estructura de archivos también es la misma. Solo hay tres archivos en uno. haga clic en:
.pch
.pch p>
AdsApple.h
AdsApple.m
1.m
2: agregado a cocoApple.m
2: Agregar a cocoApple.h
AdsApple.m
2: Agregar a cocoApple .m
2: Agregue a cocos2dx la administración unificada de PluginManager, luego nuestra nueva clase debe heredar InterfaceAds y vincularse a iAd.framework.
3: Es casi la 1 en punto, vaya directamente al código, complete los comentarios:
Archivo de encabezado:
//p>
/ / AdsApple
// AdsApple
//
// Creado por kevin el 14-5-2.#import
#import "iAd/iAd.h"
#import "InterfaceAds.h"
// Tipos de anuncios
typedef enum {
kTypeBanner = 1, // adbar
kTypeFullScreen, // pantalla completa
}AppleType;
@interface AdsApple : NSObject
{
}
@property BOOL depuración;
@property bool bannerVisible;
@property int bannerPos;
@property (assign, nonatomic) ADBannerView* bannerView;
// Establecer información del desarrollador
- (void) configDeveloperInfo: (NSMutableDictionary*) devInfo;
// Mostrar anuncios
- (void) showAds: (NSMutableDictionary*) posición de información: (int) pos; p>
// Ocultar anuncios
- (void) hideAds: ( NSMutableDictionary*) info;
// posición obtener
- (void) queryPoints; p>
//
- (void) gastarPoints: (int) puntos;
// Cambiar modo de depuración
- ( void) setDebugMode: (BOOL) isDebugMode;
// Obtener la versión del SDK
- (NSString*) getSDKVersion;
// Obtener el complemento versión
- (NSString*) getPluginVersion;
@end
Implementación:
//
/ / AdsApple
// AdsApple
//
// Creado por kevin el 14-5-2.
//
#import "AdsApple.h"
#import "AdsWrapper.h"
#define OUTPUT_LOG( .. .) if (self.debug) NSLog(__VA_ARGS__);
#define OUT_POS CGPointMake(-1024, -1024)
@implementation AdsApple
@synthesize debug = __debug;
//Inicialización
- (id)init
{
self = [super init]; p>
if (self) {
}
return self;
}
// Liberar
- (void)dealloc
{
if ( self.bannerView ! = nil ) {
[self.bannerView removeFromSuperview];
[lanzamiento de self.bannerView];
self.bannerView = nil;
}
[super dealloc];
}
#pragma mark InterfaceAds impl
// Establecer información del desarrollador
- (void) configDeveloperInfo: (NSMutableDictionary*) devInfo
{
}
// Mostrar anuncios
- (void) showAds: (NSMutableDictionary*) posición de información: (int) pos
{
NSString* strType = [ info objectForKey:@"AppleType"];
int type = [strType intValue];
switch (tipo) {
case kTypeBanner:
{
[self showBanner: pos];
break;
}
caso kTypeFullScreen:
OUTPUT_LOG(@"Ahora no es compatible con la vista de pantalla completa en AppleType");
break;
predeterminado:
OUTPUT_LOG(@"El valor de 'AppleType' es incorrecto (debe ser 1 o 2)");
break;
}
}
- (void ) hideAds: (NSMutableDictionary*) info
{
NSString* strType = [info objectForKey:@"AppleType"];
int tipo = [strType intValue ];
cambiar (tipo) {
caso kTypeBanner:
{
si (nulo
! = self.bannerView) {
[self.bannerView removeFromSuperview];
[lanzamiento de self.bannerView];
self.bannerView = nil;
}
break;
}
case kTypeFullScreen:
OUTPUT_LOG(@"Ahora no es compatible vista de pantalla completa en AppleType");
break;
predeterminado:
OUTPUT_LOG(@"El valor de AppleType es incorrecto (debe ser 1 o 2) ");
descanso;
}
}
- (nulo) queryPoints
{ p>
OUTPUT_LOG(@"AdsApple no admite puntos de consulta!");
}
- (void) gastarPoints: (int) puntos
{
OUTPUT_LOG(@ "¡AdsApple no admite puntos de gasto!");
}
- (void) setDebugMode: (BOOL) isDebugMode p>
{
self.debug = isDebugMode;
}
- (NSString*) getSDKVersion
{ p>
return @"6.4.2";
}
- (NSString*) getPluginVersion
{
return @" 0.2.0";
}
// Mostrar banner
- (void) showBanner: (int) pos
{
// Eliminar si existe, volver a crear
if (nil != self.bannerView) {
[self.bannerView removeFromSuperview];
[lanzamiento de self.bannerView];
self.bannerView = nil;
}
// Crear
self.bannerView = [[ADBannerView alloc] initWithFrame:CGRectZero];
self.bannerView.frame = CGRectOffset( self.bannerView.frame = CGRectOffset( self.bannerView.frame = CGRectOffset( self. bannerView. frame = CGRectOffset()))))ADBannerContentSizeIdentifierPortrait];
self.bannerView.requiredContentSizeIdentifiers = [NSSet setWithObject.currentContentSizeIdentifier = ADBannerContentSizeIdenti
fierPortrait;
self.bannerView.delegate=self;
[AdsWrapper addAdView:self.bannerView atPos:pos];
self.bannerView.center = OUT_POS ;
self.bannerPos = pos;
[UIView commitAnimations];
self.bannerView.center = OUT_POS;
// Enviar una notificación al oyente de que el clic en el anuncio se cerró correctamente
[AdsWrapper onPlayerGetPoints:self withPoints:1];
}
@end
4: Úselo como otros complementos, cargue, muestre, oculte, .... desinstale...
#if CC_TARGET_PLATFORM == CC_PLATFORM_IOS
m_pNowAdsPtl =dynamic_cast
if( m_pNowAdsPtl ) {
m_mapAdsInfo["AppleType"] = "1" ;
m_bUsingIAD = true;
}
# endif
5: iAd tiene notificación de eventos que cambia antes y después de hacer clic en el anuncio , para garantizar que la interfaz de monitoreo permanezca sin cambios, GetPoint le solicitará una devolución de llamada de escucha de clic después de ingresar al anuncio....
6: Algunos países no admiten iAd. cambio entre plataformas publicitarias según la zona horaria u otros métodos de detección. Utilizo la cantidad de fallas para detectar, por lo que no las enumeraré aquí.
Fin~
.