iAds en iOS 4.0 y versiones posteriores

Previous topic - Next topic

msx

Bueno, pues para el que quiera integrar iAds en su aplicación para que corra en IOS 4.0 y todas las versiones posteriores o voy a dejar los pasos que yo he seguido y que ha funcionado al menos con 4.0.2, 4.1, 4.2.1, 4.3.1 (verificado por ampos y por mí mismo).

Consiste en seguir los pasos del gran matchy (gracias) con una pequeña modificación.

1.- Al inicio de nuestra aplicación (fuera del bucle SHOWSCREEN) añadimos glb_BannerInit()
2.- Al final de nuestra aplicación añadimos:
Code (glbasic) Select
?IFDEF IPHONE
IMPORT "C" void glb_BannerInit()
?ELSE
FUNCTION glb_BannerInit:
DEBUG "[WIN] Banner Init (sim) \n"
ENDFUNCTION
?ENDIF


3.- Compilamos para Iphone.
4.- Dentro de la carpeta Proyecto\XCode\Classes creamos dos archivos AppViewController.h y AppViewController.mm.
5.- En AppViewController.h escribimos con un editor de texto:
Quote// This filename is "AppViewController.h"
#import "iAd/ADBannerView.h"
@interface AppViewController : UIViewController <ADBannerViewDelegate> {
   ADBannerView * bannerView;
   UIView * _appView;
        UIWindow * _appWindow;
}
@property (nonatomic, retain) IBOutlet UIView * appView;
@property (nonatomic, retain) IBOutlet ADBannerView * bannerView;
@property (nonatomic, retain) IBOutlet UIWindow * appWindow;
- (void)createBannerView;
- (void)showBanner;
- (void)hideBanner;
- (void)changeBannerOrientation:(UIInterfaceOrientation)toOrientation;
@end

6.- En AppViewController.mm escribimos con un editor de texto:
Code (glbasic) Select
// This filename is "AppViewController.mm"
#import "AppViewController.h"
@implementation AppViewController
@synthesize appView = _appView;
@synthesize bannerView; // = _bannerView;
@synthesize appWindow = _appWindow;
# pragma mark -
# pragma mark View
- (void)viewDidLoad {
[super viewDidLoad];
// NSLog(@"viewDidLoad");
}
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
// NSLog(@"viewDidAppear");
}
//- (void)viewWillAppear:(BOOL)animated {
// NSLog(@"viewWillAppear");
// if (bannerView) {
// UIInterfaceOrientation orientation=self.interfaceOrientation;
// [self changeBannerOrientation:orientation];
// }
//}
- (void)dealloc {
    [super dealloc];
}
//- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
//
// return (interfaceOrientation == UIInterfaceOrientationPortrait) | (interfaceOrientation == UIInterfaceOrientationLandscapeLeft) | (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
//}
#pragma mark -
#pragma mark ADBanner
//- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
//if (bannerView) {
// [self changeBannerOrientation:toInterfaceOrientation];
//}
// NSLog(@"shouldAutorotate");
//}
- (void)changeBannerOrientation:(UIInterfaceOrientation)toOrientation {
if (&ADBannerContentSizeIdentifierPortrait != nil)
{
if (UIInterfaceOrientationIsLandscape(toOrientation)) {
bannerView.currentContentSizeIdentifier=ADBannerContentSizeIdentifierLandscape;
self.view.frame=CGRectMake(0,0, 320, 120);
} else {
bannerView.currentContentSizeIdentifier=ADBannerContentSizeIdentifierPortrait;
self.view.frame=CGRectMake(0,0, 480, 100);
}
}else {
if (UIInterfaceOrientationIsLandscape(toOrientation)) {
bannerView.currentContentSizeIdentifier=ADBannerContentSizeIdentifier480x32;
self.view.frame=CGRectMake(0,0, 320, 120);
} else {
bannerView.currentContentSizeIdentifier=ADBannerContentSizeIdentifier320x50;
self.view.frame=CGRectMake(0,0, 480, 100);
}
}
}
- (void)bannerViewDidLoadAd:(ADBannerView *)banner {
NSLog(@"bannerViewDidLoad");
// self.bannerView.hidden=NO;
[self showBanner];
}
- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error {
// self.bannerView.hidden=YES;
// NSLog(@"bannerView");
NSLog(@"E R R O R: '%@'",error);
// [self hideBanner];
}
- (void)createBannerView {
// NSLog(@"Banner creating...");
_appWindow = [[UIApplication sharedApplication] keyWindow];

bannerView=[[[ADBannerView alloc] init] autorelease];
bannerView.delegate=self;

self.view.frame = CGRectMake(0,430, 768, 50);
bannerView.frame=CGRectMake(0,530, 768, 50);

if (&ADBannerContentSizeIdentifierPortrait != nil)
{
bannerView.currentContentSizeIdentifier=ADBannerContentSizeIdentifierPortrait;
} else {
bannerView.currentContentSizeIdentifier=ADBannerContentSizeIdentifier320x50;
}

[self.view addSubview:self.bannerView];

[_appWindow addSubview:self.view];
[_appWindow makeKeyWindow];
// [_appWindow makeKeyAndVisible];
}
- (void)showBanner {
// NSLog(@"Show banner");
CGRect bannerFrame=bannerView.frame;
bannerFrame.origin.y=0;
[UIView beginAnimations:@"showBanner" context:NULL];
bannerView.frame=bannerFrame;
[UIView commitAnimations];
}
- (void)hideBanner {
// NSLog(@"Hide banner");
CGRect bannerFrame=bannerView.frame;
bannerFrame.origin.y=-bannerFrame.size.height;
bannerView.frame=bannerFrame;
}
#pragma mark -
#pragma mark GLB
- (void)initBanner {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc]init];
[self performSelectorOnMainThread:@selector(createBannerView) withObject:nil waitUntilDone:YES];
[pool release];
}
@end
extern "C" void glb_BannerInit() {
AppViewController * UIGlbasic;
UIGlbasic = [[AppViewController alloc] init];
[UIGlbasic createBannerView];
// [UIGlbasic release];
[UIGlbasic retain];
}

NOTA: A diferencia del código de matchy, aquí comprobamos la existencia de la variable ADBannerContentSizeIdentifierPortrait que solo está definida a partir de iOS 4.2 y la salida del iPAD, y en función de la existencia o no, usamos la variable ADBannerContentSizeIdentifierLandscape y ADBannerContentSizeIdentifierPortrait o usamos ADBannerContentSizeIdentifier480x32 y ADBannerContentSizeIdentifier320x50, respectivamente. Esta discriminación se hace con un simple IF.
7.- Vamos a nuestro Mac o Hackintosh (como el mío).
8.- Abrimos nuestro Proyecto con XCODE.
9.- Sobre la carpeta Classes que aparece en el programa XCode (menú de la izquierda) pulsamos botón derecho y seleccionamos Add Files.
10.- Añadimos los archivos AppViewController.h y AppViewController.mm.
11.- Expandimos el directorio Target, y sobre el nombre de nuestro proyecto (iPhone) pulsamos botón derecho y elegimos Get Info.
12.- Seleccionamos pestaña Build y seleccionamos All Configurations
13.- En Base SDK seleccionamos el que tengamos (seguramente IOS 4.2)
14.- En iPhone OS Deployment Target seleccionamos IOS 4.0.
15.- Vamos a carpeta Framework, botón derecho y Add Framework.
16.- Añadimos iAd.framework y CoreGraphics.framework (éste no sé si es necesario pero yo lo pongo).
17.- Build y a esperar...

Bueno, espero que os sirva, si alguien quiere traducirlo... que tenga paciencia  :D

También he adjuntado un archivo RAR, con los ficheros que hay que crear por si a alguien no le apetece trabajar tanto  =D

Saludosssss  :enc: :enc:

Actualizado tutorial, totalmente operativo para iOS>=4.0

[attachment deleted by admin]

mentalthink

Hola Msx, gracias por la info, es realment útil, en la próxima apliación que haga, voy a intentar estos pasos.

Un saludo, y gracias de nuevo, por este tuto, super bueno. Espero que haya más ;)

Iván J.

Hark0

Muy bueno!

Habrá que probarlo en un futuro :P
http://litiopixel.blogspot.com
litiopixel.blogspot.com - Desarrollo videojuegos Indie · Pixel-Art · Retroinformática · Electrónica Development Indie Videogames · Pixel-Art · Retrocomputing · Electronic

msx


kaotiklabs

Entiendo que este código te muestra siempre el banner por pantalla.

Yo necesito habilitarlo en ciertas partes del juego pero en otras no.
¿hay alguna manera de habilitarlo/deshabilitarlo?
Vote Cthulhu! Because the stars are right!!!!
Ia Ia Cthulhu F' tang!

ampos

¿Al final lo conseguiste?

En teoría solo debe funcionar en 4-0 y superiores. Versiones anteriores no tienen soporte de iAds.

Actualizaré mi prog con publi a tu version y lo pruebo, ke pa algo tengo 6 iphones pa probar  :nana:
check my web and/or my blog :D
http://diniplay.blogspot.com (devblog)
http://www.ampostata.org
http://ampostata.blogspot.com
I own PC-Win, MacBook 13", iPhone 3G/3GS/4G and iPAC-WinCE

kaotiklabs

Lo conseguí a medias.
Me funciona pero no consigo de ninguna manera poner el banner en landscape y que siga funcionando los inputs de la tactil.
¿alguien ha conseguido hacerlo funcionar en landscape?
Vote Cthulhu! Because the stars are right!!!!
Ia Ia Cthulhu F' tang!

pinete

Diooos que curro.... estoy haciéndome viejo....   :sick:

msx

Quote from: ampos on 2011-Mar-31
¿Al final lo conseguiste?

En teoría solo debe funcionar en 4-0 y superiores. Versiones anteriores no tienen soporte de iAds.

Actualizaré mi prog con publi a tu version y lo pruebo, ke pa algo tengo 6 iphones pa probar  :nana:

Te hubieses enterado si nos visitaras mas a menudo, que solo hablas con los de la lengua de Shakespeare.  :nana:

P.D.: Si puedes pruebalo en IOS 4.3.1 y confírmanos que funciona.

kaotiklabs


¿alguien ha conseguido hacerlo funcionar en landscape?
No logro conseguirlo...
Vote Cthulhu! Because the stars are right!!!!
Ia Ia Cthulhu F' tang!

msx

¿alguien me confirma que mis instrucciones funcionan en IOS 4.3.1? He tenido problemas con un Review que me han echado para atrás porque no arranca y no sé si es de eso o de otra cosa.

msx

Quote from: msx on 2011-Apr-03
¿alguien me confirma que mis instrucciones funcionan en IOS 4.3.1? He tenido problemas con un Review que me han echado para atrás porque no arranca y no sé si es de eso o de otra cosa.

¿alguien me hace este favor en un iOS 4.3?

Eternamente agradecido.  :happy:

ampos

Yo tengo ke hacerlo pero estoy muy liado.

Y creo ke estoy en 4.2.1...
check my web and/or my blog :D
http://diniplay.blogspot.com (devblog)
http://www.ampostata.org
http://ampostata.blogspot.com
I own PC-Win, MacBook 13", iPhone 3G/3GS/4G and iPAC-WinCE

msx

Me vale el 4.2, por favor pruebalo cuando puedas, creo que no sirve para versiones posteriores a 4.1, habrá que buscar otra solución de compatibilidad.

ampos

Si me pones ya el codigo definitivo, lo pruebo...
check my web and/or my blog :D
http://diniplay.blogspot.com (devblog)
http://www.ampostata.org
http://ampostata.blogspot.com
I own PC-Win, MacBook 13", iPhone 3G/3GS/4G and iPAC-WinCE