iOS: Greystripe SDK w/ Monkey
Monkey Forums/Monkey Code/iOS: Greystripe SDK w/ Monkey
| ||
Native iOS Code: NOTE: While the Greystripe SDK can serve banner ads, this code is for fullscreen ads only NOTE: There is no harm calling '*_Init' during resumes and/or "*_UnInit" during suspends /* ** Greystripe.cpp */ #import "GSAdView.h" #import "GSAdEngine.h" #import "GreystripeDelegate.h" @class _GreystripeDelegate; #define _GREYSTRIPE_SLOT_NAME @"adSlot" static bool _greystripe_adEngineReady; static bool _greystripe_isFullscreen; static _GreystripeDelegate* _greystripe_adDelegate; @interface _GreystripeDelegate: UIViewController <GreystripeDelegate> {} @end @implementation _GreystripeDelegate - (void)greystripeAdReadyForSlotNamed:(NSString *)a_name { printf( "%s: %s\n", __func__, [a_name cStringUsingEncoding:NSASCIIStringEncoding] ); } - (void)greystripeFullScreenDisplayWillOpen { printf( "%s\n", __func__ ); _greystripe_isFullscreen = true; } - (void)greystripeFullScreenDisplayWillClose { printf( "%s\n", __func__ ); _greystripe_isFullscreen = false; } @end void Greystripe_Init( String AppID ) { printf( "%s\n", __func__ ); if( !(([[[UIDevice currentDevice] systemVersion] floatValue] >= 3.2f) && ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad)) ) { if( !_greystripe_adDelegate ) { _greystripe_adDelegate = [[_GreystripeDelegate alloc] init]; if( !_greystripe_adEngineReady ) { _greystripe_adEngineReady = true; GSAdSlotDescription* slot = [GSAdSlotDescription descriptionWithSize:kGSAdSizeIPhoneFullScreen name:_GREYSTRIPE_SLOT_NAME]; [GSAdEngine startupWithAppID:AppID.ToNSString() adSlotDescriptions:[NSArray arrayWithObjects:slot, nil]]; [GSAdEngine setFullScreenDelegate:_greystripe_adDelegate forSlotNamed:_GREYSTRIPE_SLOT_NAME]; } } } } void Greystripe_UnInit() { printf( "%s\n", __func__ ); if( _greystripe_adDelegate ) { [_greystripe_adDelegate release]; _greystripe_adDelegate = nil; } } bool Greystripe_RequestAd() { printf( "%s -> ", __func__ ); if( _greystripe_adDelegate ) { if( [GSAdEngine isAdReadyForSlotNamed:_GREYSTRIPE_SLOT_NAME] ) { [GSAdEngine displayFullScreenAdForSlotNamed:_GREYSTRIPE_SLOT_NAME]; printf( "Ok.\n" ); return true; } } printf( "Not Available.\n" ); return false; } bool Greystripe_IsFullscreen() { return _greystripe_isFullscreen; } Monkey Interface: 'greystripe.monkey Private Import "greystripe.cpp" Extern Function Greystripe_Init:Void( AppID$ ) Function Greystripe_UnInit:Void() Function Greystripe_RequestAd?() Function Greystripe_IsFullscreen?() Usage: 'main.monkey Import greystripe Function Main() Greystripe_Init( "app-id-here" ) Greystripe_RequestAd '<-- will very likely return false (no-ad-ready) because the SDK has not had time to buffer ad End Enjoy! |