Last active
December 17, 2015 23:49
-
-
Save flurrydev/5692311 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import "FlurryAdDelegate.h" | |
#import "FlurryAds.h" | |
/** | |
* You can integrate interstitials in any placement in your app, but for | |
* testing purposes we present integration within your ViewController | |
*/ | |
- (void)viewWillAppear:(BOOL)animated { | |
[super viewWillAppear:animated]; | |
// Register yourself as a delegate for ad callbacks | |
[FlurryAds setAdDelegate:self]; | |
// Fetch fullscreen ads early when a later display is likely. For | |
// example, at the beginning of a level. | |
[FlurryAds fetchAdForSpace:@"INTERSTITIAL_MAIN_VIEW" | |
frame:self.view.frame size:FULLSCREEN]; | |
// For the purpose of demonstration we will start a timer to show | |
// full screen ads. Note: an interstitial will not display if another | |
// interstitial is currently displaying. | |
int64_t delay = 5; | |
NSDate *d = [NSDate dateWithTimeIntervalSinceNow: delay]; | |
// Note the timer should be referenced and invalidated in viewWillDisappear. | |
// We are foregoing this as it is not related to demonstrating interstitial display | |
NSTimer *t = [[[NSTimer alloc] initWithFireDate: d | |
interval: delay | |
target: self | |
selector:@selector(showFullScreenAd:) | |
userInfo:nil repeats:YES] autorelease]; | |
NSRunLoop *runner = [NSRunLoop currentRunLoop]; | |
[runner addTimer:t forMode: NSDefaultRunLoopMode]; | |
} | |
-(void) viewWillDisappear:(BOOL)animated { | |
[super viewWillDisappear:animated]; | |
// Reset delegate | |
[FlurryAds setAdDelegate:nil]; | |
} | |
/** | |
* Invoke a takeover at a natural pause in your app. For example, when a | |
* level is completed, an article is read or a button is pressed. | |
*/ | |
-(void) showFullScreenAd:(NSTimer *)timer { | |
// Check if ad is ready. If so, display the ad | |
if ([FlurryAds adReadyForSpace:@"INTERSTITIAL_MAIN_VIEW"]) { | |
[FlurryAds displayAdForSpace:@"INTERSTITIAL_MAIN_VIEW" | |
onView:self.view]; | |
} else { | |
// Fetch an ad | |
[FlurryAds fetchAdForSpace:@"INTERSTITIAL_MAIN_VIEW" | |
frame:self.view.frame size:FULLSCREEN]; | |
} | |
} | |
/* | |
* It is recommended to pause app activities when an interstitial is shown. | |
* Listen to should display delegate. | |
*/ | |
- (BOOL) spaceShouldDisplay:(NSString*)adSpace interstitial:(BOOL) | |
interstitial { | |
if (interstitial) { | |
NSLog(@"Pause app state now"); | |
} | |
// Continue ad display | |
return YES; | |
} | |
/* | |
* Resume app state when the interstitial is dismissed. | |
*/ | |
- (void)spaceDidDismiss:(NSString *)adSpace interstitial:(BOOL)interstitial { | |
if (interstitial) { | |
NSLog(@"Resume app state here"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment