Skip to content

Instantly share code, notes, and snippets.

@pjlaird
Last active December 19, 2015 06:49
Show Gist options
  • Select an option

  • Save pjlaird/5913782 to your computer and use it in GitHub Desktop.

Select an option

Save pjlaird/5913782 to your computer and use it in GitHub Desktop.
Tap For Tap MoPub iOS Custom Events
#import "MPBannerCustomEvent.h"
#import "TapForTapAdView.h"
@interface TapForTapBannerMoPubCustomEvent : MPBannerCustomEvent <TapForTapAdViewDelegate>
@property (retain, nonatomic) TapForTapAdView *adView;
@end
#import "TapForTapBannerMoPubCustomEvent.h"
#import "TapForTap.h"
@implementation TapForTapBannerMoPubCustomEvent
-(id) init {
self = [super init];
if (self) {
[TapForTap initializeWithAPIKey:@"YOUR API KEY"];
self.adView = [[TapForTapAdView alloc] initWithFrame:CGRectZero delegate:self];
self.adView.autoRollover = false;
}
return self;
}
-(void) dealloc {
self.adView.delegate = nil;
[_adView release];
self.adView = nil;
[super dealloc];
}
-(void) requestAdWithSize:(CGSize)size customEventInfo:(NSDictionary *)info {
self.adView.frame = [self frameForCustomEventInfo:info];
CLLocation *location = self.delegate.location;
if (location) {
[TapForTap setLocation:location];
}
[self.adView loadAds];
}
- (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) tapForTapAdViewDidReceiveAd:(TapForTapAdView *)adView {
[self.delegate bannerCustomEvent:self didLoadAd:adView];
}
-(void) tapForTapAdView:(TapForTapAdView *)adView didFailToReceiveAd:(NSString *)reason {
[self.delegate bannerCustomEvent:self didFailToLoadAdWithError:nil];
}
-(void) tapForTapAdViewWasTapped:(TapForTapAdView *)adView {
[self.delegate bannerCustomEventWillLeaveApplication:self];
}
@end
#import "MPInterstitialCustomEvent.h"
#import "TapForTapInterstitial.h"
@interface TapForTapInterstitialMoPubCustomEvent : MPInterstitialCustomEvent <TapForTapInterstitialDelegate>
@end
#import "TapForTapInterstitialMoPubCustomEvent.h"
#import "TapForTap.h"
#import "TapForTapInterstitial.h"
@implementation TapForTapInterstitialMoPubCustomEvent
- (id) init {
self = [super init];
if (self) {
[TapForTap initializeWithAPIKey:@"YOUR API KEY"];
[TapForTapInterstitial prepareWithDelegate:self];
}
return self;
}
- (void) dealloc {
[TapForTapInterstitial setDelegate:nil];
[super dealloc];
}
- (void)requestInterstitialWithCustomEventInfo:(NSDictionary *)info
{
[TapForTapInterstitial prepareWithDelegate: self];
// If Tap for Tap already has an interstitial ready let MoPub know
if ([TapForTapInterstitial isReady]) {
[self.delegate interstitialCustomEvent:self didLoadAd:self];
}
CLLocation *location = self.delegate.location;
if (location) {
[TapForTap setLocation:location];
}
}
- (void)showInterstitialFromRootViewController:(UIViewController *)rootViewController
{
[TapForTapInterstitial showWithRootViewController:rootViewController];
}
- (void) tapForTapInterstitialDidReceiveAd {
[self.delegate interstitialCustomEvent:self didLoadAd:self];
}
- (void) tapForTapInterstitialFailedToDownload:(NSString *)reason {
[self.delegate interstitialCustomEvent:self didFailToLoadAdWithError:nil];
}
- (void) tapForTapInterstitialDidShow {
[self.delegate interstitialCustomEventDidAppear:self];
}
- (void) tapForTapInterstitialWasDismissed {
[self.delegate interstitialCustomEventDidDisappear:self];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment