# HG changeset patch # User John Tsiombikas # Date 1442606570 -10800 # Node ID 2d5abf441307b31454f53571a1fbd225ca31b01b # Parent 7841e93650657d7827b127e66b6c951f68b784e6 ads done diff -r 7841e9365065 -r 2d5abf441307 src/ios/viewctl.h --- a/src/ios/viewctl.h Wed Sep 16 07:10:02 2015 +0300 +++ b/src/ios/viewctl.h Fri Sep 18 23:02:50 2015 +0300 @@ -3,8 +3,9 @@ #import #import +#import -@interface ViewController : GLKViewController +@interface ViewController : GLKViewController @end #endif /* VIEWCTL_H_ */ diff -r 7841e9365065 -r 2d5abf441307 src/ios/viewctl.m --- a/src/ios/viewctl.m Wed Sep 16 07:10:02 2015 +0300 +++ b/src/ios/viewctl.m Fri Sep 18 23:02:50 2015 +0300 @@ -3,10 +3,16 @@ @interface ViewController () { EAGLContext *ctx; + + ADBannerView *ad; + BOOL ad_visible; } -- (void)initgl; -- (void)destroygl; + +- (void)create_ad; + +- (void)init_gl; +- (void)destroy_gl; @end @implementation ViewController @@ -24,12 +30,15 @@ view.context = self->ctx; view.drawableDepthFormat = GLKViewDrawableDepthFormat24; - [self initgl]; + [self create_ad]; + + + [self init_gl]; } - (void)dealloc { - [self destroygl]; + [self destroy_gl]; if([EAGLContext currentContext] == self->ctx) { [EAGLContext setCurrentContext: nil]; @@ -43,7 +52,7 @@ if([self isViewLoaded] && ([[self view] window] == nil)) { self.view = nil; - [self destroygl]; + [self destroy_gl]; if([EAGLContext currentContext] == self->ctx) { [EAGLContext setCurrentContext: nil]; @@ -59,25 +68,55 @@ return YES; } -- (void)initgl +- (void)create_ad +{ + ad_visible = NO; + ad = [[ADBannerView alloc] initWithAdType: ADAdTypeBanner]; + [ad setAutoresizingMask: UIViewAutoresizingFlexibleWidth]; + ad.frame = CGRectOffset(ad.frame, 0, -ad.frame.size.height); + [self.view addSubview: ad]; + ad.delegate = self; +} + +- (void)init_gl { [EAGLContext setCurrentContext: self->ctx]; glClearColor(1.0, 0.0, 0.0, 1.0); } -- (void)destroygl +- (void)destroy_gl { [EAGLContext setCurrentContext: self->ctx]; } -- (void)update -{ -} - (void)glkView: (GLKView*)view drawInRect: (CGRect)rect { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); } +// ADBannerDelegate functions + +- (void)bannerViewDidLoadAd: (ADBannerView*)banner +{ + if(!ad_visible) { + CGRect rect = ad.frame; + rect.origin.y = 0; + ad.frame = rect; + ad_visible = YES; + } +} + +- (void)bannerView: (ADBannerView*)banner didFailToReceiveAdWithError: (NSError*)error +{ + if(ad_visible) { + ad_visible = NO; + ad.frame = CGRectOffset(ad.frame, 0, -ad.frame.size.height); + } + + NSLog(@"Failed to retrieve ad"); +} + + @end /* implementation ViewController */