Created
September 13, 2014 00:19
-
-
Save flurrydev/53356b1283655a15b08b 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 "Flurry_Stream_Setup.h" | |
#import "FlurryAdStreamDelegate.h" | |
#import "FlurryAdTargeting.h" | |
#import "FlurryAd.h" | |
@interface MyViewController : UIViewController <FlurryAdStreamDelegate> | |
@property (nonatomic, retain) FlurryAdStream *streamAd; | |
@end | |
@implementation Flurry_Stream_Setup | |
- (void)viewDidLoad { | |
[super viewDidDload]; | |
self.streamAd = [[FlurryAd alloc] initWithSpace:@"STREAM_VIEW" size:FL_STREAM_300x250]; | |
FlurryAdTargeting *adTargeting = [self targetingForDevice]; | |
streamAd.adDelegate = self; | |
streamAd.targeting = adTargeting; | |
[streamAd fetchAd]; | |
} | |
- (void) viewWillAppear:(bool)animated { | |
[super viewWillAppear]; | |
[self.streamAd registerAdActiveWithViewController:self]; | |
} | |
- (void) viewWillDisappear:(bool)animated { | |
[self.streamAd pauseAd]; | |
} | |
-(void)dealloc { | |
// your dealloc code | |
self.streamAd = nil; | |
[super dealloc]; | |
} | |
- (FlurryAdTargeting *)targetingForDevice | |
{ | |
// Pass all targeting options. This will increase revenue dramatically | |
FlurryAdTargeting *adTargeting = [FlurryAdTargeting targeting]; | |
adTargeting.location = [self getCurrentCLLocation]; | |
adTargeting.gender = FL_FEMALE; | |
adTargeting.age = 25; | |
return adTargeting; | |
} | |
// Handle a click on a sample table view | |
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { | |
NSDictionary* cellProperties = [self.tableObjs objectAtIndex:[indexPath row]]; | |
FlurryAd *flurryAd = [cellProperties valueForKey:@"adObj"]; | |
if (flurryAd != nil) { | |
// User clicked on FlurryAd | |
[flurryAd callClickAction]; | |
} else { | |
// Invoke normal logic | |
} | |
[tableView deselectRowAtIndexPath:indexPath animated:YES]; | |
} | |
// Recommended Delegate methods to implement (for list of all delegates see <link>) | |
/******* for stream non-native ******/ | |
- (void) adStreamDidFetchAd:(FlurryAdStream *)flurryAd | |
{ | |
// Show the ad if desired | |
[self.view addSubView:flurryAd]; | |
[flurryAd registerAdActiveWithViewController:self]; | |
} | |
/******* for stream native ******/ | |
- (void) adStreamDidFetchAd:(FlurryAdStream *)flurryAd | |
{ | |
// pull native assets | |
FlurryNativeAssets *nativeAssets = flurryAd.nativeAssets; | |
if (nativeAssets == nil) { | |
// This is configured on the server (probably) so update there? | |
return; | |
} | |
// Icon and mainImage handle impression tracking and clicks. All native ads require one or both of these | |
UIView *mainImage = nativeAssets.mainImageWithTracking; | |
UIView *icon = nativeAssets.iconWithTracking; | |
NSString *title = nativeAssets.title; | |
NSString *description = nativeAssets.description; | |
NSString *callToActionText = nativeAssets.callToAction; | |
// Connect button to [flurryAd handleClick]; | |
[self.viewContainer addSubView:viewForConstructedAd]; | |
// // Let's say we're putting this at position 5 in a tableview and you want to know that if the ad is interacted with | |
// flurryAd.appProperties = [NSDictionary dictionaryWithObject:[NSNumber numberWithInt:5] forKey:@"tableIdx"]; | |
// Show the ad if desired | |
[self.view addSubView:self.viewContainer]; | |
[flurryAd registerAdDispalyedWithViewController:self]; | |
} | |
- (void) adStreamDidFailToFetchAd:(FlurryAdStream *)flurryAd error:(NSError *)error | |
{ | |
// Handle failure to receive ad. This can be calling another network or waiting some time to try again | |
} | |
- (void) adStreamDidFailToRender:(FlurryAdStream *)flurryAd error:(NSError *)error | |
{ | |
// Tried to display ad, but there was a failure (for example, failure in video play) | |
// Get position this item was in table display and remove | |
// NSNumber adIdx = [flurryAd.appProperties objectForKey:@"tableIdx"]; | |
// Remove view at this ad index | |
} | |
- (void)adStreamDidDismissFullscreen:(FlurryAdStream *)flurryAd | |
{ | |
// Handle the closing of the ad. Restart sound in game for example | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment