istereo2

changeset 1:2d5abf441307

ads done
author John Tsiombikas <nuclear@member.fsf.org>
date Fri, 18 Sep 2015 23:02:50 +0300
parents 7841e9365065
children 81d35769f546
files src/ios/viewctl.h src/ios/viewctl.m
diffstat 2 files changed, 51 insertions(+), 11 deletions(-) [+]
line diff
     1.1 --- a/src/ios/viewctl.h	Wed Sep 16 07:10:02 2015 +0300
     1.2 +++ b/src/ios/viewctl.h	Fri Sep 18 23:02:50 2015 +0300
     1.3 @@ -3,8 +3,9 @@
     1.4  
     1.5  #import <UIKit/UIKit.h>
     1.6  #import <GLKit/GLKit.h>
     1.7 +#import <iAd/iAd.h>
     1.8  
     1.9 -@interface ViewController : GLKViewController
    1.10 +@interface ViewController : GLKViewController <ADBannerViewDelegate>
    1.11  @end
    1.12  
    1.13  #endif	/* VIEWCTL_H_ */
     2.1 --- a/src/ios/viewctl.m	Wed Sep 16 07:10:02 2015 +0300
     2.2 +++ b/src/ios/viewctl.m	Fri Sep 18 23:02:50 2015 +0300
     2.3 @@ -3,10 +3,16 @@
     2.4  
     2.5  @interface ViewController () {
     2.6  	EAGLContext *ctx;
     2.7 +
     2.8 +	ADBannerView *ad;
     2.9 +	BOOL ad_visible;
    2.10  }
    2.11  
    2.12 -- (void)initgl;
    2.13 -- (void)destroygl;
    2.14 +
    2.15 +- (void)create_ad;
    2.16 +
    2.17 +- (void)init_gl;
    2.18 +- (void)destroy_gl;
    2.19  @end
    2.20  
    2.21  @implementation ViewController
    2.22 @@ -24,12 +30,15 @@
    2.23      view.context = self->ctx;
    2.24      view.drawableDepthFormat = GLKViewDrawableDepthFormat24;
    2.25  
    2.26 -	[self initgl];
    2.27 +	[self create_ad];
    2.28 +
    2.29 +
    2.30 +	[self init_gl];
    2.31  }
    2.32  
    2.33  - (void)dealloc
    2.34  {
    2.35 -	[self destroygl];
    2.36 +	[self destroy_gl];
    2.37  
    2.38      if([EAGLContext currentContext] == self->ctx) {
    2.39          [EAGLContext setCurrentContext: nil];
    2.40 @@ -43,7 +52,7 @@
    2.41      if([self isViewLoaded] && ([[self view] window] == nil)) {
    2.42          self.view = nil;
    2.43  
    2.44 -        [self destroygl];
    2.45 +        [self destroy_gl];
    2.46  
    2.47          if([EAGLContext currentContext] == self->ctx) {
    2.48              [EAGLContext setCurrentContext: nil];
    2.49 @@ -59,25 +68,55 @@
    2.50      return YES;
    2.51  }
    2.52  
    2.53 -- (void)initgl
    2.54 +- (void)create_ad
    2.55 +{
    2.56 +	ad_visible = NO;
    2.57 +	ad = [[ADBannerView alloc] initWithAdType: ADAdTypeBanner];
    2.58 +	[ad setAutoresizingMask: UIViewAutoresizingFlexibleWidth];
    2.59 +	ad.frame = CGRectOffset(ad.frame, 0, -ad.frame.size.height);
    2.60 +	[self.view addSubview: ad];
    2.61 +	ad.delegate = self;
    2.62 +}
    2.63 +
    2.64 +- (void)init_gl
    2.65  {
    2.66      [EAGLContext setCurrentContext: self->ctx];
    2.67  
    2.68  	glClearColor(1.0, 0.0, 0.0, 1.0);
    2.69  }
    2.70  
    2.71 -- (void)destroygl
    2.72 +- (void)destroy_gl
    2.73  {
    2.74      [EAGLContext setCurrentContext: self->ctx];
    2.75  }
    2.76  
    2.77 -- (void)update
    2.78 -{
    2.79 -}
    2.80  
    2.81  - (void)glkView: (GLKView*)view drawInRect: (CGRect)rect
    2.82  {
    2.83      glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    2.84  }
    2.85  
    2.86 +// ADBannerDelegate functions
    2.87 +
    2.88 +- (void)bannerViewDidLoadAd: (ADBannerView*)banner
    2.89 +{
    2.90 +	if(!ad_visible) {
    2.91 +		CGRect rect = ad.frame;
    2.92 +		rect.origin.y = 0;
    2.93 +		ad.frame = rect;
    2.94 +		ad_visible = YES;
    2.95 +	}
    2.96 +}
    2.97 +
    2.98 +- (void)bannerView: (ADBannerView*)banner didFailToReceiveAdWithError: (NSError*)error
    2.99 +{
   2.100 +	if(ad_visible) {
   2.101 +		ad_visible = NO;
   2.102 +		ad.frame = CGRectOffset(ad.frame, 0, -ad.frame.size.height);
   2.103 +	}
   2.104 +
   2.105 +	NSLog(@"Failed to retrieve ad");
   2.106 +}
   2.107 +
   2.108 +
   2.109  @end	/* implementation ViewController */