Skip to content

Instantly share code, notes, and snippets.

@pjlaird
Created September 9, 2013 23:15
Show Gist options
  • Save pjlaird/6502787 to your computer and use it in GitHub Desktop.
Save pjlaird/6502787 to your computer and use it in GitHub Desktop.
iOS MoPub custom events for Tap for Tap SDK v3
//
// Copyright (c) 2013 Tap for Tap. All rights reserved.
//
#import "MPBannerCustomEvent.h"
#import "TFTTapForTap.h"
@interface TFTMoPubBanner : MPBannerCustomEvent <TFTBannerDelegate>
@property (nonatomic, retain) TFTBanner *banner;
@end
//
// Copyright (c) 2013 Tap for Tap. All rights reserved.
//
#import "TFTMoPubBanner.h"
@implementation TFTMoPubBanner
-(id) init {
self = [super init];
if (self) {
[TFTTapForTap initializeWithAPIKey:@"YOUR_API_KEY"];
}
return self;
}
-(void) dealloc {
self.banner.delegate = nil;
self.banner = nil;
}
-(void) requestAdWithSize:(CGSize)size customEventInfo:(NSDictionary *)info {
self.banner = [TFTBanner bannerWithFrame:[self frameForCustomEventInfo:info] delegate:self];
self.banner.forceLoad = YES;
self.banner.autoRollover = NO;
CLLocation *location = self.delegate.location;
if (location) {
[TFTTapForTap setLocation:location];
}
[self.banner startShowingAds];
}
- (CGRect)frameForCustomEventInfo:(NSDictionary *)info
{
CGFloat width = [[info objectForKey:@"adWidth"] floatValue];
CGFloat height = [[info objectForKey:@"adHeight"] floatValue];
if (width < 320 && height < 50) {
width = 320;
height = 50;
}
return CGRectMake(0, 0, width, height);
}
-(void) tftBannerDidReceiveAd:(TFTBanner *)banner {
// Must user self.banner as in 3.0.2 the banner returned is nil. Will be fix in next release.
[self.delegate bannerCustomEvent:self didLoadAd:self.banner];
}
-(void) tftBanner:(TFTBanner *)banner didFailToReceiveAd:(NSString *)reason {
[self.delegate bannerCustomEvent:self didFailToLoadAdWithError:nil];
}
-(void) tftBannerWasTapped:(TFTBanner *)banner {
[self.delegate bannerCustomEventWillLeaveApplication:self];
}
@end
//
// Copyright (c) 2013 Tap for Tap. All rights reserved.
//
#import "MPInterstitialCustomEvent.h"
#import "TFTTapForTap.h"
@interface TFTMoPubInterstitial : MPInterstitialCustomEvent <TFTInterstitialDelegate>
@property (nonatomic, retain) TFTInterstitial *interstitial;
@end
//
// Copyright (c) 2013 Tap for Tap. All rights reserved.
//
#import "TFTMoPubInterstitial.h"
@implementation TFTMoPubInterstitial
- (id) init {
self = [super init];
if (self) {
[TFTTapForTap initializeWithAPIKey:@"YOUR _API_KEY"];
self.interstitial = [TFTInterstitial interstitialWithDelegate:self];
}
return self;
}
- (void) dealloc {
self.interstitial = nil;
}
- (void)requestInterstitialWithCustomEventInfo:(NSDictionary *)info
{
[self.interstitial load];
// If Tap for Tap already has an interstitial ready let MoPub know
if (self.interstitial.readyToShow) {
[self.delegate interstitialCustomEvent:self didLoadAd:self];
}
CLLocation *location = self.delegate.location;
if (location) {
[TFTTapForTap setLocation:location];
}
}
- (void)showInterstitialFromRootViewController:(UIViewController *)rootViewController {
[self.interstitial showWithViewController:rootViewController];
}
- (void)tftInterstitialDidReceiveAd:(TFTInterstitial *)interstitial {
[self.delegate interstitialCustomEvent:self didLoadAd:self];
}
- (void)tftInterstitial:(TFTInterstitial *)interstitial didFail:(NSString *)reason {
[self.delegate interstitialCustomEvent:self didFailToLoadAdWithError:nil];
}
- (void)tftInterstitialDidShow:(TFTInterstitial *)interstitial {
[self.delegate interstitialCustomEventDidAppear:self];
}
- (void)tftInterstitialWasTapped:(TFTInterstitial *)interstitial {
[self.delegate interstitialCustomEventDidReceiveTapEvent:self];
}
- (void) tftInterstitialWasDismissed:(TFTInterstitial *)interstitial {
[self.delegate interstitialCustomEventDidDisappear:self];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment