adding adNetwork SDKs for AdWhirl and AdMob
This commit is contained in:
@@ -0,0 +1,128 @@
|
||||
/*
|
||||
|
||||
AdWhirlAdNetworkAdapter.h
|
||||
|
||||
Copyright 2009 AdMob, Inc.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
*/
|
||||
|
||||
#import "AdWhirlDelegateProtocol.h"
|
||||
#import "AdWhirlConfig.h"
|
||||
|
||||
typedef enum {
|
||||
AdWhirlAdNetworkTypeAdMob = 1,
|
||||
AdWhirlAdNetworkTypeJumpTap = 2,
|
||||
AdWhirlAdNetworkTypeVideoEgg = 3,
|
||||
AdWhirlAdNetworkTypeMedialets = 4,
|
||||
AdWhirlAdNetworkTypeLiveRail = 5,
|
||||
AdWhirlAdNetworkTypeMillennial = 6,
|
||||
AdWhirlAdNetworkTypeGreyStripe = 7,
|
||||
AdWhirlAdNetworkTypeQuattro = 8,
|
||||
AdWhirlAdNetworkTypeCustom = 9,
|
||||
AdWhirlAdNetworkTypeAdWhirl10 = 10,
|
||||
AdWhirlAdNetworkTypeMobClix = 11,
|
||||
AdWhirlAdNetworkTypeMdotM = 12,
|
||||
AdWhirlAdNetworkTypeAdWhirl13 = 13,
|
||||
AdWhirlAdNetworkTypeGoogleAdSense = 14,
|
||||
AdWhirlAdNetworkTypeGoogleDoubleClick = 15,
|
||||
AdWhirlAdNetworkTypeGeneric = 16,
|
||||
AdWhirlAdNetworkTypeEvent = 17,
|
||||
AdWhirlAdNetworkTypeInMobi = 18,
|
||||
AdWhirlAdNetworkTypeIAd = 19,
|
||||
AdWhirlAdNetworkTypeZestADZ = 20,
|
||||
AdWhirlAdNetworkTypeBrightRoll = 21,
|
||||
AdWhirlAdNetworkTypeTapAd = 22,
|
||||
AdWhirlAdNetworkTypeOneRiot = 23,
|
||||
AdWhirlAdNetworkTypeNexage = 24
|
||||
} AdWhirlAdNetworkType;
|
||||
|
||||
@class AdWhirlView;
|
||||
@class AdWhirlConfig;
|
||||
@class AdWhirlAdNetworkConfig;
|
||||
|
||||
@interface AdWhirlAdNetworkAdapter : NSObject {
|
||||
id<AdWhirlDelegate> adWhirlDelegate;
|
||||
AdWhirlView *adWhirlView;
|
||||
AdWhirlConfig *adWhirlConfig;
|
||||
AdWhirlAdNetworkConfig *networkConfig;
|
||||
UIView *adNetworkView;
|
||||
}
|
||||
|
||||
/**
|
||||
* Subclasses must implement +networkType to return an AdWhirlAdNetworkType enum.
|
||||
*/
|
||||
//+ (AdWhirlAdNetworkType)networkType;
|
||||
|
||||
/**
|
||||
* Subclasses must add itself to the AdWhirlAdNetworkRegistry. One way
|
||||
* to do so is to implement the +load function and register there.
|
||||
*/
|
||||
//+ (void)load;
|
||||
|
||||
/**
|
||||
* Default initializer. Subclasses do not need to override this method unless
|
||||
* they need to perform additional initialization. In which case, this
|
||||
* method must be called via the super keyword.
|
||||
*/
|
||||
- (id)initWithAdWhirlDelegate:(id<AdWhirlDelegate>)delegate
|
||||
view:(AdWhirlView *)view
|
||||
config:(AdWhirlConfig *)config
|
||||
networkConfig:(AdWhirlAdNetworkConfig *)netConf;
|
||||
|
||||
/**
|
||||
* Ask the adapter to get an ad. This must be implemented by subclasses.
|
||||
*/
|
||||
- (void)getAd;
|
||||
|
||||
/**
|
||||
* When called, the adapter must remove itself as a delegate or notification
|
||||
* observer from the underlying ad network SDK. Subclasses must implement this
|
||||
* method, even if the underlying SDK doesn't have a way of removing delegate
|
||||
* (in which case, you should contact the ad network). Note that this method
|
||||
* will be called in dealloc at AdWhirlAdNetworkAdapter, before adNetworkView
|
||||
* is released. Care must be taken if you also keep a reference of your ad view
|
||||
* in a separate instance variable, as you may have released that variable
|
||||
* before this gets called in AdWhirlAdNetworkAdapter's dealloc. Use
|
||||
* adNetworkView, defined in this class, instead of your own instance variable.
|
||||
* This function should also be idempotent, i.e. get called multiple times and
|
||||
* not crash.
|
||||
*/
|
||||
- (void)stopBeingDelegate;
|
||||
|
||||
/**
|
||||
* Subclasses return YES to ask AdWhirlView to send metric requests to the
|
||||
* AdWhirl server for ad impressions. Default is YES.
|
||||
*/
|
||||
- (BOOL)shouldSendExMetric;
|
||||
|
||||
/**
|
||||
* Tell the adapter that the interface orientation changed or is about to change
|
||||
*/
|
||||
- (void)rotateToOrientation:(UIInterfaceOrientation)orientation;
|
||||
|
||||
/**
|
||||
* Some ad transition types may cause issues with particular ad networks. The
|
||||
* adapter should know whether the given animation type is OK. Defaults to
|
||||
* YES.
|
||||
*/
|
||||
- (BOOL)isBannerAnimationOK:(AWBannerAnimationType)animType;
|
||||
|
||||
@property (nonatomic,assign) id<AdWhirlDelegate> adWhirlDelegate;
|
||||
@property (nonatomic,assign) AdWhirlView *adWhirlView;
|
||||
@property (nonatomic,retain) AdWhirlConfig *adWhirlConfig;
|
||||
@property (nonatomic,retain) AdWhirlAdNetworkConfig *networkConfig;
|
||||
@property (nonatomic,retain) UIView *adNetworkView;
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
AdWhirlAdapterBrightRoll.h
|
||||
|
||||
Copyright 2010 BrightRoll, Inc.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
*/
|
||||
|
||||
#import "AdWhirlAdNetworkAdapter.h"
|
||||
#import "BRBannerAd.h"
|
||||
#import "BRBannerAdDelegate.h"
|
||||
#import "BRFullScreenAd.h"
|
||||
#import "BRFullScreenAdDelegate.h"
|
||||
|
||||
@interface AdWhirlAdapterBrightRoll : AdWhirlAdNetworkAdapter <BRBannerAdDelegate, BRFullScreenAdDelegate>
|
||||
{
|
||||
BRBannerAd *brBannerAd;
|
||||
}
|
||||
|
||||
@property (nonatomic, retain) BRBannerAd *brBannerAd;
|
||||
|
||||
+ (AdWhirlAdNetworkType)networkType;
|
||||
- (void)brBannerAdFetched:(BRBannerAd *)brBannerAd;
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,137 @@
|
||||
/*
|
||||
|
||||
AdWhirlAdapterBrightRoll.m
|
||||
|
||||
Copyright 2009 BrightRoll, Inc.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
*/
|
||||
|
||||
#import "AdWhirlAdapterBrightRoll.h"
|
||||
#import "AdWhirlAdNetworkAdapter.h"
|
||||
#import "AdWhirlAdNetworkRegistry.h"
|
||||
#import "AdWhirlView.h"
|
||||
#import "AdWhirlAdNetworkAdapter+Helpers.h"
|
||||
#import "AdWhirlAdNetworkConfig.h"
|
||||
|
||||
@implementation AdWhirlAdapterBrightRoll
|
||||
|
||||
@synthesize brBannerAd;
|
||||
|
||||
+ (AdWhirlAdNetworkType)networkType
|
||||
{
|
||||
return AdWhirlAdNetworkTypeBrightRoll;
|
||||
}
|
||||
|
||||
+ (void)load
|
||||
{
|
||||
[[AdWhirlAdNetworkRegistry sharedRegistry] registerClass:self];
|
||||
}
|
||||
|
||||
- (void)stopObserving
|
||||
{
|
||||
[[NSNotificationCenter defaultCenter]
|
||||
removeObserver:self
|
||||
name:@"AdWhirlViewWillAnimateToNewAd"
|
||||
object:self.adWhirlView];
|
||||
}
|
||||
|
||||
- (void)stopBeingDelegate
|
||||
{
|
||||
[self stopObserving];
|
||||
self.brBannerAd.delegate = nil;
|
||||
self.brBannerAd = nil;
|
||||
}
|
||||
|
||||
- (void)getAd
|
||||
{
|
||||
self.brBannerAd = [BRBannerAd fetchWithDelegate:self];
|
||||
}
|
||||
|
||||
#pragma mark BRBannerAdDelegate required methods
|
||||
|
||||
- (NSString *)brBannerAdAppId:(BRBannerAd *)theBrBannerAd
|
||||
{
|
||||
if ([adWhirlDelegate respondsToSelector:@selector(brightRollAppId)])
|
||||
{
|
||||
return [adWhirlDelegate brightRollAppId];
|
||||
}
|
||||
return networkConfig.pubId;
|
||||
}
|
||||
|
||||
- (void)brBannerAdFetched:(BRBannerAd *)theBrBannerAd
|
||||
{
|
||||
[[NSNotificationCenter defaultCenter]
|
||||
addObserver:self
|
||||
selector:@selector(adWhirlWillAnimateToNewAdIn:)
|
||||
name:@"AdWhirlViewWillAnimateToNewAd"
|
||||
object:self.adWhirlView];
|
||||
|
||||
brBannerAd.fullScreenAd.delegate = self;
|
||||
self.adNetworkView = brBannerAd.view;
|
||||
[self.adWhirlView adapter:self didReceiveAdView:brBannerAd.view];
|
||||
}
|
||||
|
||||
- (void)brBannerAdFetchFailed:(BRBannerAd *)bannerAd
|
||||
{
|
||||
[adWhirlView
|
||||
adapter:self
|
||||
didFailAd:[NSError
|
||||
errorWithDomain:@"com.brightroll.BrightRoll_iPhone_SDK"
|
||||
code:404
|
||||
userInfo:[NSDictionary dictionary]]];
|
||||
}
|
||||
|
||||
- (void)brBannerAdWillShowFullScreenAd:(BRBannerAd *)bannerAd
|
||||
{
|
||||
[self helperNotifyDelegateOfFullScreenModal];
|
||||
}
|
||||
|
||||
#pragma mark AdWhirlView notification methods
|
||||
|
||||
- (void)adWhirlWillAnimateToNewAdIn:(NSNotification *)notification
|
||||
{
|
||||
if ([self.adWhirlView performSelector:@selector(currAdapter)] == self)
|
||||
{
|
||||
[self stopObserving];
|
||||
[self helperNotifyDelegateOfFullScreenModal];
|
||||
[brBannerAd.fullScreenAd show];
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark BRFullScreenAdDelegate required methods
|
||||
|
||||
- (UIViewController *)brFullScreenAdControllerParent
|
||||
{
|
||||
return [self.adWhirlDelegate viewControllerForPresentingModalView];
|
||||
}
|
||||
|
||||
- (void)brFullScreenAdDismissed:(BRFullScreenAd *)brFullScreenAd
|
||||
{
|
||||
[self helperNotifyDelegateOfFullScreenModalDismissal];
|
||||
}
|
||||
|
||||
- (NSString *)brightRollAppId
|
||||
{
|
||||
NSString *appId = [self.networkConfig.credentials objectForKey:@"pubid"];
|
||||
|
||||
if (!appId)
|
||||
{
|
||||
appId = [self.adWhirlDelegate brightRollAppId];
|
||||
}
|
||||
|
||||
return appId;
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
|
||||
AdWhirlAdapterGoogleAdMobAds.h
|
||||
Copyright 2011 Google, Inc.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
*/
|
||||
|
||||
#import "AdWhirlAdNetworkAdapter.h"
|
||||
#import "GADBannerViewDelegate.h"
|
||||
|
||||
@interface AdWhirlAdapterGoogleAdMobAds : AdWhirlAdNetworkAdapter
|
||||
<GADBannerViewDelegate> {
|
||||
}
|
||||
|
||||
- (SEL)delegatePublisherIdSelector;
|
||||
- (NSString *)hexStringFromUIColor:(UIColor *)color;
|
||||
+ (AdWhirlAdNetworkType)networkType;
|
||||
- (NSString *)publisherId;
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,199 @@
|
||||
/*
|
||||
|
||||
AdWhirlAdapterGoogleAdMobAds.m
|
||||
Copyright 2011 Google, Inc.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
*/
|
||||
|
||||
#import "AdWhirlAdapterGoogleAdMobAds.h"
|
||||
#import "AdWhirlAdNetworkConfig.h"
|
||||
#import "AdWhirlView.h"
|
||||
#import "GADBannerView.h"
|
||||
#import "AdWhirlLog.h"
|
||||
#import "AdWhirlAdNetworkAdapter+Helpers.h"
|
||||
#import "AdWhirlAdNetworkRegistry.h"
|
||||
|
||||
@implementation AdWhirlAdapterGoogleAdMobAds
|
||||
|
||||
+ (void)load {
|
||||
[[AdWhirlAdNetworkRegistry sharedRegistry] registerClass:self];
|
||||
}
|
||||
|
||||
+ (AdWhirlAdNetworkType)networkType {
|
||||
return AdWhirlAdNetworkTypeAdMob;
|
||||
}
|
||||
|
||||
// converts UIColor to hex string, ignoring alpha.
|
||||
- (NSString *)hexStringFromUIColor:(UIColor *)color {
|
||||
CGColorSpaceModel colorSpaceModel =
|
||||
CGColorSpaceGetModel(CGColorGetColorSpace(color.CGColor));
|
||||
if (colorSpaceModel == kCGColorSpaceModelRGB
|
||||
|| colorSpaceModel == kCGColorSpaceModelMonochrome) {
|
||||
const CGFloat *colors = CGColorGetComponents(color.CGColor);
|
||||
CGFloat red = 0.0, green = 0.0, blue = 0.0;
|
||||
if (colorSpaceModel == kCGColorSpaceModelRGB) {
|
||||
red = colors[0];
|
||||
green = colors[1];
|
||||
blue = colors[2];
|
||||
// we ignore alpha here.
|
||||
} else if (colorSpaceModel == kCGColorSpaceModelMonochrome) {
|
||||
red = green = blue = colors[0];
|
||||
}
|
||||
return [NSString stringWithFormat:@"%02X%02X%02X",
|
||||
(int)(red * 255), (int)(green * 255), (int)(blue * 255)];
|
||||
}
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (NSObject *)delegateValueForSelector:(SEL)selector {
|
||||
return ([adWhirlDelegate respondsToSelector:selector]) ?
|
||||
[adWhirlDelegate performSelector:selector] : nil;
|
||||
}
|
||||
|
||||
- (void)getAd {
|
||||
GADRequest *request = [GADRequest request];
|
||||
NSObject *value;
|
||||
|
||||
NSMutableDictionary *additional = [NSMutableDictionary dictionary];
|
||||
if ([adWhirlDelegate respondsToSelector:@selector(adWhirlTestMode)]
|
||||
&& [adWhirlDelegate adWhirlTestMode]) {
|
||||
[additional setObject:@"on" forKey:@"adtest"];
|
||||
}
|
||||
|
||||
if ((value = [self delegateValueForSelector:
|
||||
@selector(adWhirlAdBackgroundColor)])) {
|
||||
[additional setObject:[self hexStringFromUIColor:(UIColor *)value]
|
||||
forKey:@"color_bg"];
|
||||
}
|
||||
|
||||
if ((value = [self delegateValueForSelector:
|
||||
@selector(adWhirlAdBackgroundColor)])) {
|
||||
[additional setObject:[self hexStringFromUIColor:(UIColor *)value]
|
||||
forKey:@"color_text"];
|
||||
}
|
||||
|
||||
// deliberately don't allow other color specifications.
|
||||
|
||||
if ([additional count] > 0) {
|
||||
request.additionalParameters = additional;
|
||||
}
|
||||
|
||||
CLLocation *location =
|
||||
(CLLocation *)[self delegateValueForSelector:@selector(locationInfo)];
|
||||
|
||||
if ((adWhirlConfig.locationOn) && (location)) {
|
||||
[request setLocationWithLatitude:location.coordinate.latitude
|
||||
longitude:location.coordinate.longitude
|
||||
accuracy:location.horizontalAccuracy];
|
||||
}
|
||||
|
||||
NSString *string =
|
||||
(NSString *)[self delegateValueForSelector:@selector(gender)];
|
||||
|
||||
if ([string isEqualToString:@"m"]) {
|
||||
request.gender = kGADGenderMale;
|
||||
} else if ([string isEqualToString:@"f"]) {
|
||||
request.gender = kGADGenderFemale;
|
||||
} else {
|
||||
request.gender = kGADGenderUnknown;
|
||||
}
|
||||
|
||||
if ((value = [self delegateValueForSelector:@selector(dateOfBirth)])) {
|
||||
request.birthday = (NSDate *)value;
|
||||
}
|
||||
|
||||
if ((value = [self delegateValueForSelector:@selector(keywords)])) {
|
||||
NSArray *keywordArray =
|
||||
[(NSString *)value componentsSeparatedByString:@" "];
|
||||
request.keywords = [NSMutableArray arrayWithArray:keywordArray];
|
||||
}
|
||||
|
||||
// Set the frame for this view to match the bounds of the parent adWhirlView.
|
||||
GADBannerView *view =
|
||||
[[GADBannerView alloc] initWithFrame:adWhirlView.bounds];
|
||||
|
||||
view.adUnitID = [self publisherId];
|
||||
view.delegate = self;
|
||||
view.rootViewController =
|
||||
[adWhirlDelegate viewControllerForPresentingModalView];
|
||||
|
||||
self.adNetworkView = [view autorelease];
|
||||
|
||||
[view loadRequest:request];
|
||||
}
|
||||
|
||||
- (void)stopBeingDelegate {
|
||||
if (self.adNetworkView != nil
|
||||
&& [self.adNetworkView respondsToSelector:@selector(setDelegate:)]) {
|
||||
[self.adNetworkView performSelector:@selector(setDelegate:)
|
||||
withObject:nil];
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark Ad Request Lifecycle Notifications
|
||||
|
||||
// Sent when an ad request loaded an ad. This is a good opportunity to add
|
||||
// this view to the hierarchy if it has not yet been added.
|
||||
- (void)adViewDidReceiveAd:(GADBannerView *)adView {
|
||||
[adWhirlView adapter:self didReceiveAdView:adView];
|
||||
}
|
||||
|
||||
// Sent when an ad request failed. Normally this is because no network
|
||||
// connection was available or no ads were available (i.e. no fill).
|
||||
- (void)adView:(GADBannerView *)adView
|
||||
didFailToReceiveAdWithError:(GADRequestError *)error {
|
||||
[adWhirlView adapter:self didFailAd:error];
|
||||
}
|
||||
|
||||
#pragma mark Click-Time Lifecycle Notifications
|
||||
|
||||
// Sent just before presenting the user a full screen view, such as a browser,
|
||||
// in response to clicking on an ad. Use this opportunity to stop animations,
|
||||
// time sensitive interactions, etc.
|
||||
//
|
||||
// Normally the user looks at the ad, dismisses it, and control returns to your
|
||||
// application by calling adViewDidDismissScreen:. However if the user hits
|
||||
// the Home button or clicks on an App Store link your application will end.
|
||||
// On iOS 4.0+ the next method called will be applicationWillResignActive: of
|
||||
// your UIViewController (UIApplicationWillResignActiveNotification).
|
||||
// Immediately after that adViewWillLeaveApplication: is called.
|
||||
- (void)adViewWillPresentScreen:(GADBannerView *)adView {
|
||||
[self helperNotifyDelegateOfFullScreenModal];
|
||||
}
|
||||
|
||||
// Sent just after dismissing a full screen view. Use this opportunity to
|
||||
// restart anything you may have stopped as part of adViewWillPresentScreen:.
|
||||
- (void)adViewDidDismissScreen:(GADBannerView *)adView {
|
||||
[self helperNotifyDelegateOfFullScreenModalDismissal];
|
||||
}
|
||||
|
||||
#pragma mark parameter gathering methods
|
||||
|
||||
- (SEL)delegatePublisherIdSelector {
|
||||
return @selector(admobPublisherID);
|
||||
}
|
||||
|
||||
- (NSString *)publisherId {
|
||||
SEL delegateSelector = [self delegatePublisherIdSelector];
|
||||
|
||||
if ((delegateSelector) &&
|
||||
([adWhirlDelegate respondsToSelector:delegateSelector])) {
|
||||
return [adWhirlDelegate performSelector:delegateSelector];
|
||||
}
|
||||
|
||||
return networkConfig.pubId;
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
|
||||
AdWhirlAdapterGoogleAdSense.h
|
||||
|
||||
Copyright 2009 AdMob, Inc.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
*/
|
||||
|
||||
#import "AdWhirlAdNetworkAdapter.h"
|
||||
#import "GADAdViewController.h"
|
||||
#import "GADAdSenseParameters.h"
|
||||
#import "AdWhirlAdNetworkConfig.h"
|
||||
#import "AdWhirlAdNetworkRegistry.h"
|
||||
#import "AdWhirlView.h"
|
||||
|
||||
@interface AdWhirlAdapterGoogleAdSense : AdWhirlAdNetworkAdapter <GADAdViewControllerDelegate> {
|
||||
GADAdViewController *adViewController;
|
||||
}
|
||||
|
||||
@property (retain) GADAdViewController *adViewController;
|
||||
|
||||
+ (NSInteger)networkType;
|
||||
|
||||
- (NSString *)publisherId;
|
||||
- (NSString *)companyName;
|
||||
- (NSString *)appName;
|
||||
- (NSString *)applicationAppleID;
|
||||
- (NSNumber *)testMode;
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,189 @@
|
||||
/*
|
||||
|
||||
AdWhirlAdapterGoogleAdSense.m
|
||||
|
||||
Copyright 2009 AdMob, Inc.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
*/
|
||||
|
||||
#import "AdWhirlAdNetworkAdapter+Helpers.h"
|
||||
#import "AdWhirlAdapterGoogleAdSense.h"
|
||||
#import "AdWhirlAdNetworkConfig.h"
|
||||
#import "AdWhirlConfig.h"
|
||||
#import "AdWhirlLog.h"
|
||||
|
||||
static NSDictionary *GASParamNameToSel;
|
||||
|
||||
@implementation AdWhirlAdapterGoogleAdSense
|
||||
|
||||
@synthesize adViewController;
|
||||
|
||||
+ (NSInteger)networkType {
|
||||
return AdWhirlAdNetworkTypeGoogleAdSense;
|
||||
}
|
||||
|
||||
+ (void)load {
|
||||
[[AdWhirlAdNetworkRegistry sharedRegistry] registerClass:self];
|
||||
GASParamNameToSel = [[NSDictionary alloc] initWithObjectsAndKeys:
|
||||
@"googleAdSenseKeywords", kGADAdSenseKeywords,
|
||||
@"googleAdSenseAppWebContentURL", kGADAdSenseAppWebContentURL,
|
||||
@"googleAdSenseChannelIDs", kGADAdSenseChannelIDs,
|
||||
@"googleAdSenseAdType", kGADAdSenseAdType,
|
||||
@"googleAdSenseHostID", kGADAdSenseHostID,
|
||||
@"adWhirlAdBackgroundColor", kGADAdSenseAdBackgroundColor,
|
||||
@"googleAdSenseAdTopBackgroundColor", kGADAdSenseAdTopBackgroundColor,
|
||||
@"googleAdSenseAdBorderColor", kGADAdSenseAdBorderColor,
|
||||
@"googleAdSenseAdLinkColor", kGADAdSenseAdLinkColor,
|
||||
@"adWhirlTextColor", kGADAdSenseAdTextColor,
|
||||
@"googleAdSenseAdURLColor", kGADAdSenseAdURLColor,
|
||||
@"googleAdSenseAlternateAdColor", kGADAdSenseAlternateAdColor,
|
||||
@"googleAdSenseAlternateAdURL", kGADAdSenseAlternateAdURL,
|
||||
@"googleAdSenseAllowAdsafeMedium", kGADAdSenseAllowAdsafeMedium,
|
||||
nil];
|
||||
}
|
||||
|
||||
- (id)initWithAdWhirlDelegate:(id<AdWhirlDelegate>)delegate
|
||||
view:(AdWhirlView *)view
|
||||
config:(AdWhirlConfig *)config
|
||||
networkConfig:(AdWhirlAdNetworkConfig *)netConf {
|
||||
self = [super initWithAdWhirlDelegate:delegate
|
||||
view:view
|
||||
config:config
|
||||
networkConfig:netConf];
|
||||
if (self != nil) {
|
||||
// Check that the required methods are implemented.
|
||||
if (![delegate respondsToSelector:@selector(googleAdSenseCompanyName)]) {
|
||||
[NSException raise:NSInvalidArgumentException format:
|
||||
@"You must implement googleAdSenseCompanyName in your AdwhirlDelegate in order to use Google AdSense"];
|
||||
}
|
||||
if (![delegate respondsToSelector:@selector(googleAdSenseAppName)]) {
|
||||
[NSException raise:NSInvalidArgumentException format:
|
||||
@"You must implement googleAdSenseAppName in your AdwhirlDelegate in order to use Google AdSense"];
|
||||
}
|
||||
if (![delegate respondsToSelector:@selector(googleAdSenseApplicationAppleID)]) {
|
||||
[NSException raise:NSInvalidArgumentException format:
|
||||
@"You must implement googleAdSenseApplicationAppleID in your AdwhirlDelegate in order to use Google AdSense"];
|
||||
}
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)getAd {
|
||||
adViewController = [[GADAdViewController alloc] initWithDelegate:self];
|
||||
|
||||
NSMutableDictionary *attributes = [NSMutableDictionary dictionaryWithObjectsAndKeys:
|
||||
[self publisherId], kGADAdSenseClientID,
|
||||
[self companyName], kGADAdSenseCompanyName,
|
||||
[self appName], kGADAdSenseAppName,
|
||||
[self applicationAppleID], kGADAdSenseApplicationAppleID,
|
||||
[self testMode], kGADAdSenseIsTestAdRequest,
|
||||
nil];
|
||||
|
||||
// optional params
|
||||
for (NSString *paramName in GASParamNameToSel) {
|
||||
SEL sel = NSSelectorFromString((NSString *)[GASParamNameToSel objectForKey:paramName]);
|
||||
if ([adWhirlDelegate respondsToSelector:sel]) {
|
||||
NSObject *val = [adWhirlDelegate performSelector:sel];
|
||||
if (val != nil) {
|
||||
[attributes setObject:val forKey:paramName];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
AWLogDebug(@"Google AdSense attributes: %@", attributes);
|
||||
// load the ad
|
||||
adViewController.adSize = kGADAdSize320x50;
|
||||
[adViewController loadGoogleAd:attributes];
|
||||
adViewController.view.frame = kAdWhirlViewDefaultFrame;
|
||||
self.adNetworkView = adViewController.view;
|
||||
}
|
||||
|
||||
- (void)stopBeingDelegate {
|
||||
if (adViewController != nil) {
|
||||
adViewController.delegate = nil;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)dealloc {
|
||||
// need to call here cos adViewController will be nil when super dealloc runs
|
||||
[self stopBeingDelegate];
|
||||
[adViewController release], adViewController = nil;
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
#pragma mark parameter gathering methods
|
||||
|
||||
- (NSString *)publisherId {
|
||||
if ([adWhirlDelegate respondsToSelector:@selector(googleAdSenseClientID)]) {
|
||||
return [adWhirlDelegate googleAdSenseClientID];
|
||||
}
|
||||
|
||||
return networkConfig.pubId;
|
||||
}
|
||||
|
||||
- (NSString *)companyName {
|
||||
return [adWhirlDelegate googleAdSenseCompanyName];
|
||||
}
|
||||
|
||||
- (NSString *)appName {
|
||||
return [adWhirlDelegate googleAdSenseAppName];
|
||||
}
|
||||
|
||||
- (NSString *)applicationAppleID {
|
||||
return [adWhirlDelegate googleAdSenseApplicationAppleID];
|
||||
}
|
||||
|
||||
- (NSNumber *)testMode {
|
||||
if ([adWhirlDelegate respondsToSelector:@selector(adWhirlTestMode)]
|
||||
&& [adWhirlDelegate adWhirlTestMode]) {
|
||||
return [NSNumber numberWithInt:1];
|
||||
}
|
||||
return [NSNumber numberWithInt:0];
|
||||
}
|
||||
|
||||
#pragma mark GADAdViewControllerDelegate required methods
|
||||
|
||||
- (UIViewController *)viewControllerForModalPresentation:(GADAdViewController *)adController {
|
||||
return [adWhirlDelegate viewControllerForPresentingModalView];
|
||||
}
|
||||
|
||||
#pragma mark GADAdViewControllerDelegate notification methods
|
||||
|
||||
- (void)loadSucceeded:(GADAdViewController *)adController withResults:(NSDictionary *)results {
|
||||
[adWhirlView adapter:self didReceiveAdView:[adController view]];
|
||||
}
|
||||
|
||||
- (void)loadFailed:(GADAdViewController *)adController withError:(NSError *) error {
|
||||
[adWhirlView adapter:self didFailAd:error];
|
||||
}
|
||||
|
||||
- (GADAdClickAction)adControllerActionModelForAdClick:(GADAdViewController *)adController {
|
||||
[self helperNotifyDelegateOfFullScreenModal];
|
||||
return GAD_ACTION_DISPLAY_INTERNAL_WEBSITE_VIEW; // full screen web view
|
||||
}
|
||||
|
||||
- (void)adControllerDidCloseWebsiteView:(GADAdViewController *)adController {
|
||||
[self helperNotifyDelegateOfFullScreenModalDismissal];
|
||||
}
|
||||
|
||||
- (void)adControllerDidExpandAd:(GADAdViewController *)controller {
|
||||
[self helperNotifyDelegateOfFullScreenModal];
|
||||
}
|
||||
|
||||
- (void)adControllerDidCollapseAd:(GADAdViewController *)controller {
|
||||
[self helperNotifyDelegateOfFullScreenModalDismissal];
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
|
||||
AdWhirlAdapterGreystripe.m
|
||||
|
||||
Copyright 2010 Greystripe, Inc.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
*/
|
||||
|
||||
#import "AdWhirlAdNetworkAdapter.h"
|
||||
#import "GreystripeDelegate.h"
|
||||
|
||||
/**
|
||||
* Banner slot name used to identify the banner ad slot within the Greystripe
|
||||
* SDK.
|
||||
*/
|
||||
extern NSString * const kGSBannerSlotName;
|
||||
|
||||
/**
|
||||
* Full-screen slot name used to identify the full-screen ad slot within the
|
||||
* Greystripe SDK. Use this slot name to display full-screen ads as follows:
|
||||
*
|
||||
* [GSAdEngine displayFullScreenAdForSlotNamed:kGSFullScreenSlotName];
|
||||
*
|
||||
* If you need to check whether an ad is available for this slot, simply use:
|
||||
*
|
||||
* [GSAdEngine isAdReadyForSlotNamed:kGSFullScreenSlotName];
|
||||
*/
|
||||
extern NSString * const kGSFullScreenSlotName;
|
||||
|
||||
@class GSAdView;
|
||||
|
||||
@interface AdWhirlAdapterGreystripe : AdWhirlAdNetworkAdapter <GreystripeDelegate> {
|
||||
UIView *innerContainer;
|
||||
UIView *outerContainer;
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,191 @@
|
||||
/*
|
||||
|
||||
AdWhirlAdapterGreystripe.m
|
||||
|
||||
Copyright 2010 Greystripe, Inc.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
*/
|
||||
|
||||
#import "AdWhirlAdapterGreystripe.h"
|
||||
|
||||
#import "AdWhirlAdNetworkAdapter+Helpers.h"
|
||||
#import "AdWhirlAdNetworkConfig.h"
|
||||
#import "AdWhirlAdNetworkRegistry.h"
|
||||
#import "AdWhirlLog.h"
|
||||
#import "AdWhirlView.h"
|
||||
#import "GSAdView.h"
|
||||
#import "GSAdEngine.h"
|
||||
|
||||
// constants
|
||||
NSString * const kGSBannerSlotName = @"gsBanner";
|
||||
NSString * const kGSFullScreenSlotName = @"gsFullScreen";
|
||||
|
||||
// static globals
|
||||
static BOOL g_didStartUpGreystripe;
|
||||
static NSTimeInterval g_lastAdReadyTime;
|
||||
|
||||
@interface AdWhirlAdapterGreystripe ()
|
||||
- (void)bannerAdReady;
|
||||
@end
|
||||
|
||||
@implementation AdWhirlAdapterGreystripe
|
||||
|
||||
+ (AdWhirlAdNetworkType)networkType {
|
||||
return AdWhirlAdNetworkTypeGreyStripe;
|
||||
}
|
||||
|
||||
+ (void)load {
|
||||
[[AdWhirlAdNetworkRegistry sharedRegistry] registerClass:self];
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the Greystripe adapter. The GSAdEngine will be started up the
|
||||
* first time this method is called, using the ID provided by the AdWhirl
|
||||
* server. Two slots will be registered with the GSAdEngine: one banner and one
|
||||
* full-screen. See the note in AdWhirlAdapterGreystripe.h on how to make use
|
||||
* of the full-screen slot.
|
||||
*/
|
||||
- (id)initWithAdWhirlDelegate:(id<AdWhirlDelegate>)delegate
|
||||
view:(AdWhirlView *)view
|
||||
config:(AdWhirlConfig *)config
|
||||
networkConfig:(AdWhirlAdNetworkConfig *)netConf {
|
||||
if(self = [super initWithAdWhirlDelegate:delegate view:view config:config networkConfig:netConf]) {
|
||||
if(!g_didStartUpGreystripe) {
|
||||
@try {
|
||||
GSAdSlotDescription * bannerSlot = [GSAdSlotDescription descriptionWithSize:kGSAdSizeBanner name:kGSBannerSlotName];
|
||||
GSAdSlotDescription * fullScreenSlot = [GSAdSlotDescription descriptionWithSize:kGSAdSizeIPhoneFullScreen name:kGSFullScreenSlotName];
|
||||
[GSAdEngine startupWithAppID:netConf.pubId adSlotDescriptions:[NSArray arrayWithObjects:bannerSlot,fullScreenSlot, nil]];
|
||||
g_didStartUpGreystripe = YES;
|
||||
}
|
||||
@catch (NSException *e) {
|
||||
// This exception is thrown when Greystripe is initialized twice. We
|
||||
// ignore it because if the host app is using Greystripe directly for
|
||||
// full-screen ads, it may have already initialized Greystripe before
|
||||
// AdWhirl tried to do the same.
|
||||
if([e.name isEqualToString:NSInternalInconsistencyException]){
|
||||
g_didStartUpGreystripe = YES;
|
||||
}
|
||||
else {
|
||||
@throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Fetch a banner ad from Greystripe. This method only fetches banners as all
|
||||
* full-screen ad fetching is performed implicitly by the GSAdEngine.
|
||||
*/
|
||||
- (void)getAd {
|
||||
GSAdView *gsAdView = [GSAdView adViewForSlotNamed:kGSBannerSlotName delegate:self];
|
||||
|
||||
// Use default frame, slightly bigger, to be the parent view of gsAdView, so
|
||||
// when the GSAdView finds its containing view it stops at the inner Container
|
||||
// and will set the alpha of innerContainer, not the AdWhirlView
|
||||
innerContainer = [[UIView alloc] initWithFrame:kAdWhirlViewDefaultFrame];
|
||||
innerContainer.backgroundColor = [UIColor clearColor];
|
||||
[innerContainer addSubview:gsAdView];
|
||||
|
||||
// Set the outer container to be the size of the gsAdView so there are no unsightly
|
||||
// borders around the ad
|
||||
outerContainer = [[UIView alloc] initWithFrame:gsAdView.frame];
|
||||
outerContainer.backgroundColor = [UIColor clearColor];
|
||||
[outerContainer addSubview:innerContainer];
|
||||
self.adNetworkView = outerContainer;
|
||||
|
||||
NSTimeInterval now = [[NSDate date] timeIntervalSince1970];
|
||||
NSTimeInterval delta = now - g_lastAdReadyTime;
|
||||
if(delta > kGSMinimumRefreshInterval) {
|
||||
// For the initial ad display we will get an ad ready notification
|
||||
// automatically because the ad is automatically rendered
|
||||
// regardless of its refresh interval (0 here). For all other
|
||||
// displays we must force it.
|
||||
if(g_lastAdReadyTime > 0) {
|
||||
if([GSAdEngine isNextAdDownloadedForSlotNamed:kGSBannerSlotName]) {
|
||||
[gsAdView refresh];
|
||||
[self bannerAdReady];
|
||||
}
|
||||
else {
|
||||
AWLogDebug(@"Failing Greystripe banner ad request because the next "\
|
||||
"banner ad has not yet been downloaded.");
|
||||
[adWhirlView adapter:self didFailAd:nil];
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
AWLogDebug(@"Failing Greystripe ad request because Greystripe's "
|
||||
"minimum refresh interval of %f has not elapsed since the "\
|
||||
"previous banner display.", kGSMinimumRefreshInterval);
|
||||
[adWhirlView adapter:self didFailAd:nil];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop being the delegate for banner ads. In order to change the delegate for
|
||||
* full-screen Greystripe ads, see GSAdEngine's
|
||||
* setFullScreenDelegate:forSlotNamed: method.
|
||||
*/
|
||||
- (void)stopBeingDelegate {
|
||||
[GSAdView adViewForSlotNamed:kGSBannerSlotName delegate:nil];
|
||||
}
|
||||
|
||||
- (void)dealloc {
|
||||
[innerContainer release];
|
||||
[outerContainer release];
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
#pragma mark -
|
||||
#pragma mark GreystripeDelegate notification methods
|
||||
|
||||
/**
|
||||
* Delegate notification received when Greystripe has a banner ad ready.
|
||||
*/
|
||||
- (void)greystripeAdReadyForSlotNamed:(NSString *)a_name {
|
||||
if ([a_name isEqualToString:kGSBannerSlotName] && g_lastAdReadyTime == 0) {
|
||||
// Only forward on this notification for the initial notification as
|
||||
// all other notifications will be sent explicitly after checking
|
||||
// ad readiness (see getAd).
|
||||
[self bannerAdReady];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)greystripeFullScreenDisplayWillOpen {
|
||||
[self helperNotifyDelegateOfFullScreenModal];
|
||||
}
|
||||
|
||||
- (void)greystripeFullScreenDisplayWillClose {
|
||||
[self helperNotifyDelegateOfFullScreenModalDismissal];
|
||||
}
|
||||
|
||||
#pragma mark -
|
||||
#pragma mark Internal methods
|
||||
|
||||
/**
|
||||
* Notify the host app that Greystripe has received an ad. This only applies
|
||||
* banner ads that the Greystripe SDK has fetched, as readiness of full-screen
|
||||
* ads can be always be checked directly via
|
||||
* [GSAdEngine isAdReadyForSlotNamed:kGSFullScreenSlotName].
|
||||
*/
|
||||
- (void)bannerAdReady {
|
||||
AWLogDebug(@"Greystripe received banner ad.");
|
||||
g_lastAdReadyTime = [[NSDate date] timeIntervalSince1970];
|
||||
[adWhirlView adapter:self didReceiveAdView:self.adNetworkView];
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
|
||||
AdWhirlAdapterIAd.h
|
||||
|
||||
Copyright 2010 AdMob, Inc.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
*/
|
||||
|
||||
#import "AdWhirlAdNetworkAdapter.h"
|
||||
#import <iAd/ADBannerView.h>
|
||||
|
||||
@interface AdWhirlAdapterIAd : AdWhirlAdNetworkAdapter <ADBannerViewDelegate> {
|
||||
NSString *kADBannerContentSizeIdentifierPortrait;
|
||||
NSString *kADBannerContentSizeIdentifierLandscape;
|
||||
}
|
||||
|
||||
+ (AdWhirlAdNetworkType)networkType;
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,135 @@
|
||||
/*
|
||||
|
||||
AdWhirlAdapterIAd.m
|
||||
|
||||
Copyright 2010 AdMob, Inc.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
*/
|
||||
|
||||
#import "AdWhirlAdapterIAd.h"
|
||||
#import "AdWhirlAdNetworkConfig.h"
|
||||
#import "AdWhirlView.h"
|
||||
#import "AdWhirlLog.h"
|
||||
#import "AdWhirlAdNetworkAdapter+Helpers.h"
|
||||
#import "AdWhirlAdNetworkRegistry.h"
|
||||
|
||||
@implementation AdWhirlAdapterIAd
|
||||
|
||||
+ (AdWhirlAdNetworkType)networkType {
|
||||
return AdWhirlAdNetworkTypeIAd;
|
||||
}
|
||||
|
||||
+ (void)load {
|
||||
if(NSClassFromString(@"ADBannerView") != nil) {
|
||||
[[AdWhirlAdNetworkRegistry sharedRegistry] registerClass:self];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)getAd {
|
||||
ADBannerView *iAdView = [[ADBannerView alloc] initWithFrame:CGRectZero];
|
||||
kADBannerContentSizeIdentifierPortrait =
|
||||
&ADBannerContentSizeIdentifierPortrait != nil ?
|
||||
ADBannerContentSizeIdentifierPortrait :
|
||||
ADBannerContentSizeIdentifier320x50;
|
||||
kADBannerContentSizeIdentifierLandscape =
|
||||
&ADBannerContentSizeIdentifierLandscape != nil ?
|
||||
ADBannerContentSizeIdentifierLandscape :
|
||||
ADBannerContentSizeIdentifier480x32;
|
||||
iAdView.requiredContentSizeIdentifiers = [NSSet setWithObjects:
|
||||
kADBannerContentSizeIdentifierPortrait,
|
||||
kADBannerContentSizeIdentifierLandscape,
|
||||
nil];
|
||||
UIDeviceOrientation orientation;
|
||||
if ([self.adWhirlDelegate respondsToSelector:@selector(adWhirlCurrentOrientation)]) {
|
||||
orientation = [self.adWhirlDelegate adWhirlCurrentOrientation];
|
||||
}
|
||||
else {
|
||||
orientation = [UIDevice currentDevice].orientation;
|
||||
}
|
||||
|
||||
if (UIDeviceOrientationIsLandscape(orientation)) {
|
||||
iAdView.currentContentSizeIdentifier = kADBannerContentSizeIdentifierLandscape;
|
||||
}
|
||||
else {
|
||||
iAdView.currentContentSizeIdentifier = kADBannerContentSizeIdentifierPortrait;
|
||||
}
|
||||
[iAdView setDelegate:self];
|
||||
|
||||
self.adNetworkView = iAdView;
|
||||
[iAdView release];
|
||||
}
|
||||
|
||||
- (void)stopBeingDelegate {
|
||||
ADBannerView *iAdView = (ADBannerView *)self.adNetworkView;
|
||||
if (iAdView != nil) {
|
||||
iAdView.delegate = nil;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)rotateToOrientation:(UIInterfaceOrientation)orientation {
|
||||
ADBannerView *iAdView = (ADBannerView *)self.adNetworkView;
|
||||
if (iAdView == nil) return;
|
||||
if (UIInterfaceOrientationIsLandscape(orientation)) {
|
||||
iAdView.currentContentSizeIdentifier = kADBannerContentSizeIdentifierLandscape;
|
||||
}
|
||||
else {
|
||||
iAdView.currentContentSizeIdentifier = kADBannerContentSizeIdentifierPortrait;
|
||||
}
|
||||
// ADBanner positions itself in the center of the super view, which we do not
|
||||
// want, since we rely on publishers to resize the container view.
|
||||
// position back to 0,0
|
||||
CGRect newFrame = iAdView.frame;
|
||||
newFrame.origin.x = newFrame.origin.y = 0;
|
||||
iAdView.frame = newFrame;
|
||||
}
|
||||
|
||||
- (BOOL)isBannerAnimationOK:(AWBannerAnimationType)animType {
|
||||
if (animType == AWBannerAnimationTypeFadeIn) {
|
||||
return NO;
|
||||
}
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (void)dealloc {
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
#pragma mark IAdDelegate methods
|
||||
|
||||
- (void)bannerViewDidLoadAd:(ADBannerView *)banner {
|
||||
// ADBanner positions itself in the center of the super view, which we do not
|
||||
// want, since we rely on publishers to resize the container view.
|
||||
// position back to 0,0
|
||||
CGRect newFrame = banner.frame;
|
||||
newFrame.origin.x = newFrame.origin.y = 0;
|
||||
banner.frame = newFrame;
|
||||
|
||||
[adWhirlView adapter:self didReceiveAdView:banner];
|
||||
}
|
||||
|
||||
- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error {
|
||||
[adWhirlView adapter:self didFailAd:error];
|
||||
}
|
||||
|
||||
- (BOOL)bannerViewActionShouldBegin:(ADBannerView *)banner willLeaveApplication:(BOOL)willLeave {
|
||||
[self helperNotifyDelegateOfFullScreenModal];
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (void)bannerViewActionDidFinish:(ADBannerView *)banner {
|
||||
[self helperNotifyDelegateOfFullScreenModalDismissal];
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
|
||||
AdWhirlAdapterInMobi.h
|
||||
|
||||
Copyright 2010 AdMob, Inc.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
*/
|
||||
|
||||
#import "AdWhirlAdNetworkAdapter.h"
|
||||
#import "IMAdDelegate.h"
|
||||
#import "IMAdRequest.h"
|
||||
|
||||
@class InMobiAdView;
|
||||
|
||||
@interface AdWhirlAdapterInMobi : AdWhirlAdNetworkAdapter <IMAdDelegate> {
|
||||
|
||||
}
|
||||
|
||||
+ (AdWhirlAdNetworkType)networkType;
|
||||
- (NSString *)siteId;
|
||||
- (UIViewController *)rootViewControllerForAd;
|
||||
- (BOOL)testMode;
|
||||
- (Gender)gender;
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,173 @@
|
||||
/*
|
||||
|
||||
AdWhirlAdapterInMobi.m
|
||||
|
||||
Copyright 2010 AdMob, Inc.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
*/
|
||||
|
||||
#import "AdWhirlAdapterInMobi.h"
|
||||
#import "AdWhirlAdNetworkConfig.h"
|
||||
#import "AdWhirlView.h"
|
||||
#import "IMAdView.h"
|
||||
#import "IMAdRequest.h"
|
||||
#import "AdWhirlLog.h"
|
||||
#import "AdWhirlAdNetworkAdapter+Helpers.h"
|
||||
#import "AdWhirlAdNetworkRegistry.h"
|
||||
|
||||
@implementation AdWhirlAdapterInMobi
|
||||
|
||||
+ (AdWhirlAdNetworkType)networkType {
|
||||
return AdWhirlAdNetworkTypeInMobi;
|
||||
}
|
||||
|
||||
+ (void)load {
|
||||
[[AdWhirlAdNetworkRegistry sharedRegistry] registerClass:self];
|
||||
}
|
||||
|
||||
- (void)getAd {
|
||||
IMAdView *inMobiView = [[IMAdView alloc]
|
||||
initWithFrame:kAdWhirlViewDefaultFrame
|
||||
imAppId:[self siteId]
|
||||
imAdUnit:IM_UNIT_320x50
|
||||
rootViewController:[self rootViewControllerForAd]];
|
||||
[inMobiView autorelease];
|
||||
inMobiView.refreshInterval = REFRESH_INTERVAL_OFF;
|
||||
inMobiView.delegate = self;
|
||||
self.adNetworkView = inMobiView;
|
||||
|
||||
IMAdRequest *request = [IMAdRequest request];
|
||||
|
||||
if ([self testMode]) {
|
||||
request.testMode = true;
|
||||
}
|
||||
if ([adWhirlDelegate respondsToSelector:@selector(postalCode)]) {
|
||||
request.postalCode = [adWhirlDelegate postalCode];
|
||||
}
|
||||
if ([adWhirlDelegate respondsToSelector:@selector(areaCode)]) {
|
||||
request.areaCode = [adWhirlDelegate areaCode];
|
||||
}
|
||||
if ([adWhirlDelegate respondsToSelector:@selector(dateOfBirth)]) {
|
||||
NSDateFormatter *formatter = [[[NSDateFormatter alloc] init] autorelease];
|
||||
[formatter setDateFormat:@"dd-MM-yyyy"];
|
||||
request.dateOfBirth = [formatter
|
||||
stringFromDate:[adWhirlDelegate dateOfBirth]];
|
||||
}
|
||||
if ([adWhirlDelegate respondsToSelector:@selector(gender)]) {
|
||||
if ([adWhirlDelegate gender] == @"m") {
|
||||
request.gender = G_M;
|
||||
} else if ([adWhirlDelegate gender] == @"f") {
|
||||
request.gender = G_F;
|
||||
} else {
|
||||
request.gender = G_None;
|
||||
}
|
||||
}
|
||||
if ([adWhirlDelegate respondsToSelector:@selector(keywords)]) {
|
||||
request.keywords = [adWhirlDelegate keywords];
|
||||
}
|
||||
if ([adWhirlDelegate respondsToSelector:@selector(searchString)]) {
|
||||
request.searchString = [adWhirlDelegate searchString];
|
||||
}
|
||||
if ([adWhirlDelegate respondsToSelector:@selector(incomeLevel)]) {
|
||||
request.income = [adWhirlDelegate incomeLevel];
|
||||
}
|
||||
if ([adWhirlDelegate respondsToSelector:@selector(inMobiEducation)]) {
|
||||
request.education = [adWhirlDelegate inMobiEducation];
|
||||
}
|
||||
if ([adWhirlDelegate respondsToSelector:@selector(inMobiEthnicity)]) {
|
||||
request.ethnicity = [adWhirlDelegate inMobiEthnicity];
|
||||
}
|
||||
if ([adWhirlDelegate respondsToSelector:@selector(dateOfBirth)]) {
|
||||
request.age = [self helperCalculateAge];
|
||||
}
|
||||
if ([adWhirlDelegate respondsToSelector:@selector(inMobiInterests)]) {
|
||||
request.interests = [adWhirlDelegate inMobiInterests];
|
||||
}
|
||||
if ([adWhirlDelegate respondsToSelector:@selector(inMobiParamsDictionary)]) {
|
||||
request.paramsDictionary = [adWhirlDelegate inMobiParamsDictionary];
|
||||
}
|
||||
if (!adWhirlConfig.locationOn) {
|
||||
request.isLocationEnquiryAllowed = false;
|
||||
}
|
||||
|
||||
[inMobiView loadIMAdRequest:request];
|
||||
}
|
||||
|
||||
- (void)stopBeingDelegate {
|
||||
InMobiAdView *inMobiView = (InMobiAdView *)self.adNetworkView;
|
||||
if (inMobiView != nil) {
|
||||
[inMobiView setDelegate:nil];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)dealloc {
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
#pragma mark IMAdView helper methods
|
||||
|
||||
- (NSString *)siteId {
|
||||
if ([adWhirlDelegate respondsToSelector:@selector(inMobiAppId)]) {
|
||||
return [adWhirlDelegate inMobiAppID];
|
||||
}
|
||||
return networkConfig.pubId;
|
||||
}
|
||||
|
||||
- (UIViewController *)rootViewControllerForAd {
|
||||
return [adWhirlDelegate viewControllerForPresentingModalView];
|
||||
}
|
||||
|
||||
- (BOOL)testMode {
|
||||
if ([adWhirlDelegate respondsToSelector:@selector(adWhirlTestMode)])
|
||||
return [adWhirlDelegate adWhirlTestMode];
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (Gender)gender {
|
||||
if ([adWhirlDelegate respondsToSelector:@selector(gender)]) {
|
||||
NSString *genderStr = [adWhirlDelegate gender];
|
||||
if ([genderStr isEqualToString:@"f"]) {
|
||||
return G_F;
|
||||
} else if ([genderStr isEqualToString:@"m"]) {
|
||||
return G_M;
|
||||
}
|
||||
}
|
||||
return G_None;
|
||||
}
|
||||
|
||||
#pragma mark IMAdDelegate methods
|
||||
|
||||
- (void)adViewDidFinishRequest:(IMAdView *)adView {
|
||||
[adWhirlView adapter:self didReceiveAdView:adView];
|
||||
}
|
||||
|
||||
- (void)adView:(IMAdView *)view didFailRequestWithError:(IMAdError *)error {
|
||||
NSLog(@"Error %@", error);
|
||||
[adWhirlView adapter:self didFailAd:nil];
|
||||
}
|
||||
|
||||
- (void)adViewWillPresentScreen:(IMAdView *)adView {
|
||||
[self helperNotifyDelegateOfFullScreenModal];
|
||||
}
|
||||
|
||||
- (void)adViewWillDismissScreen:(IMAdView *)adView {
|
||||
[self helperNotifyDelegateOfFullScreenModalDismissal];
|
||||
}
|
||||
|
||||
- (void)adViewWillLeaveApplication:(IMAdView *)adView {
|
||||
[self helperNotifyDelegateOfFullScreenModal];
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
|
||||
AdWhirlAdapterJumpTap.h
|
||||
|
||||
Copyright 2009 AdMob, Inc.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
*/
|
||||
|
||||
#import "AdWhirlAdNetworkAdapter.h"
|
||||
#import "JTAdWidget.h"
|
||||
|
||||
@interface AdWhirlAdapterJumpTap : AdWhirlAdNetworkAdapter <JTAdWidgetDelegate> {
|
||||
|
||||
}
|
||||
|
||||
+ (AdWhirlAdNetworkType)networkType;
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,238 @@
|
||||
/*
|
||||
|
||||
AdWhirlAdapterJumpTap.m
|
||||
|
||||
Copyright 2009 AdMob, Inc.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
*/
|
||||
|
||||
#import "AdWhirlAdapterJumpTap.h"
|
||||
#import "AdWhirlView.h"
|
||||
#import "AdWhirlConfig.h"
|
||||
#import "AdWhirlAdNetworkConfig.h"
|
||||
#import "AdWhirlAdNetworkAdapter+Helpers.h"
|
||||
#import "AdWhirlAdNetworkRegistry.h"
|
||||
|
||||
|
||||
@implementation AdWhirlAdapterJumpTap
|
||||
|
||||
+ (AdWhirlAdNetworkType)networkType {
|
||||
return AdWhirlAdNetworkTypeJumpTap;
|
||||
}
|
||||
|
||||
+ (void)load {
|
||||
[[AdWhirlAdNetworkRegistry sharedRegistry] registerClass:self];
|
||||
}
|
||||
|
||||
- (void)getAd {
|
||||
JTAdWidget *widget = [[JTAdWidget alloc] initWithDelegate:self
|
||||
shouldStartLoading:YES];
|
||||
widget.frame = kAdWhirlViewDefaultFrame;
|
||||
widget.refreshInterval = 0; // do not self-refresh
|
||||
self.adNetworkView = widget;
|
||||
|
||||
if ([adWhirlDelegate respondsToSelector:@selector(jumptapTransitionType)]) {
|
||||
widget.transition = [adWhirlDelegate jumptapTransitionType];
|
||||
}
|
||||
[widget release];
|
||||
}
|
||||
|
||||
- (void)stopBeingDelegate {
|
||||
// no way to set JTAdWidget's delegate to nil
|
||||
}
|
||||
|
||||
- (void)dealloc {
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
#pragma mark JTAdWidgetDelegate methods
|
||||
|
||||
- (NSString *)publisherId:(id)theWidget {
|
||||
NSString *pubId = networkConfig.pubId;
|
||||
if (pubId == nil) {
|
||||
NSDictionary *cred = networkConfig.credentials;
|
||||
if (cred != nil) {
|
||||
pubId = [cred objectForKey:@"publisherID"];
|
||||
}
|
||||
}
|
||||
return pubId;
|
||||
}
|
||||
|
||||
- (NSString *)site:(id)theWidget {
|
||||
NSString *siteId = nil;
|
||||
if ([adWhirlDelegate respondsToSelector:@selector(jumptapSiteId)]) {
|
||||
siteId = [adWhirlDelegate jumptapSiteId];
|
||||
}
|
||||
if (siteId == nil) {
|
||||
NSDictionary *cred = networkConfig.credentials;
|
||||
if (cred != nil) {
|
||||
siteId = [cred objectForKey:@"siteID"];
|
||||
}
|
||||
}
|
||||
return siteId;
|
||||
}
|
||||
|
||||
- (NSString *)adSpot:(id)theWidget {
|
||||
NSString *spotId = nil;
|
||||
if ([adWhirlDelegate respondsToSelector:@selector(jumptapSpotId)]) {
|
||||
spotId = [adWhirlDelegate jumptapSpotId];
|
||||
}
|
||||
if (spotId == nil) {
|
||||
NSDictionary *cred = networkConfig.credentials;
|
||||
if (cred != nil) {
|
||||
spotId = [cred objectForKey:@"spotID"];
|
||||
}
|
||||
}
|
||||
return spotId;
|
||||
}
|
||||
|
||||
- (BOOL)shouldRenderAd:(id)theWidget {
|
||||
[adWhirlView adapter:self didReceiveAdView:theWidget];
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (void)beginAdInteraction:(id)theWidget {
|
||||
[self helperNotifyDelegateOfFullScreenModal];
|
||||
}
|
||||
|
||||
- (void)endAdInteraction:(id)theWidget {
|
||||
[self helperNotifyDelegateOfFullScreenModalDismissal];
|
||||
}
|
||||
|
||||
- (void)adWidget:(id)theWidget didFailToShowAd:(NSError *)error {
|
||||
[adWhirlView adapter:self didFailAd:error];
|
||||
}
|
||||
|
||||
- (void)adWidget:(id)theWidget didFailToRequestAd:(NSError *)error {
|
||||
[adWhirlView adapter:self didFailAd:error];
|
||||
}
|
||||
|
||||
- (BOOL)respondsToSelector:(SEL)selector {
|
||||
if (selector == @selector(location:)
|
||||
&& ![adWhirlDelegate respondsToSelector:@selector(locationInfo)]) {
|
||||
return NO;
|
||||
}
|
||||
else if (selector == @selector(query:)
|
||||
&& ![adWhirlDelegate respondsToSelector:@selector(keywords)]) {
|
||||
return NO;
|
||||
}
|
||||
else if (selector == @selector(category:)
|
||||
&& ![adWhirlDelegate respondsToSelector:@selector(jumptapCategory)]) {
|
||||
return NO;
|
||||
}
|
||||
else if (selector == @selector(adultContent:)
|
||||
&& ![adWhirlDelegate respondsToSelector:@selector(jumptapAdultContent)]) {
|
||||
return NO;
|
||||
}
|
||||
return [super respondsToSelector:selector];
|
||||
}
|
||||
|
||||
#pragma mark JTAdWidgetDelegate methods -Targeting
|
||||
|
||||
- (NSString *)query:(id)theWidget {
|
||||
return [adWhirlDelegate keywords];
|
||||
}
|
||||
|
||||
- (NSString *)category:(id)theWidget {
|
||||
return [adWhirlDelegate jumptapCategory];
|
||||
}
|
||||
|
||||
- (AdultContent)adultContent:(id)theWidget {
|
||||
return [adWhirlDelegate jumptapAdultContent];
|
||||
}
|
||||
|
||||
#pragma mark JTAdWidgetDelegate methods -General Configuration
|
||||
|
||||
- (NSDictionary*)extraParameters:(id)theWidget {
|
||||
NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithCapacity:10];
|
||||
if ([adWhirlDelegate respondsToSelector:@selector(dateOfBirth)]) {
|
||||
NSInteger age = [self helperCalculateAge];
|
||||
if (age >= 0)
|
||||
[dict setObject:[NSString stringWithFormat:@"%d",age] forKey:@"mt-age"];
|
||||
}
|
||||
if ([adWhirlDelegate respondsToSelector:@selector(gender)]) {
|
||||
NSString *gender = [adWhirlDelegate gender];
|
||||
if (gender != nil)
|
||||
[dict setObject:gender forKey:@"mt-gender"];
|
||||
}
|
||||
if ([adWhirlDelegate respondsToSelector:@selector(incomeLevel)]) {
|
||||
NSUInteger income = [adWhirlDelegate incomeLevel];
|
||||
NSString *level = nil;
|
||||
if (income < 15000) {
|
||||
level = @"000_015";
|
||||
}
|
||||
else if (income < 20000) {
|
||||
level = @"015_020";
|
||||
}
|
||||
else if (income < 30000) {
|
||||
level = @"020_030";
|
||||
}
|
||||
else if (income < 40000) {
|
||||
level = @"030_040";
|
||||
}
|
||||
else if (income < 50000) {
|
||||
level = @"040_050";
|
||||
}
|
||||
else if (income < 75000) {
|
||||
level = @"050_075";
|
||||
}
|
||||
else if (income < 100000) {
|
||||
level = @"075_100";
|
||||
}
|
||||
else if (income < 125000) {
|
||||
level = @"100_125";
|
||||
}
|
||||
else if (income < 150000) {
|
||||
level = @"125_150";
|
||||
}
|
||||
else {
|
||||
level = @"150_OVER";
|
||||
}
|
||||
[dict setObject:level forKey:@"mt-hhi"];
|
||||
}
|
||||
return dict;
|
||||
}
|
||||
|
||||
- (UIColor *)adBackgroundColor:(id)theWidget {
|
||||
return [self helperBackgroundColorToUse];
|
||||
}
|
||||
|
||||
- (UIColor *)adForegroundColor:(id)theWidget {
|
||||
return [self helperTextColorToUse];
|
||||
}
|
||||
|
||||
#pragma mark JTAdWidgetDelegate methods -Location Configuration
|
||||
|
||||
- (BOOL)allowLocationUse:(id)theWidget {
|
||||
return adWhirlConfig.locationOn;
|
||||
}
|
||||
|
||||
- (CLLocation*)location:(id)theWidget {
|
||||
if (![adWhirlDelegate respondsToSelector:@selector(locationInfo)]) {
|
||||
return nil;
|
||||
}
|
||||
return [adWhirlDelegate locationInfo];
|
||||
}
|
||||
|
||||
#pragma mark JTAdWidgetDelegate methods -Ad Display and User Interaction
|
||||
// The ad orientation changed
|
||||
//- (void)adWidget:(id)theWidget orientationHasChangedTo:(UIInterfaceOrientation)interfaceOrientation;
|
||||
|
||||
// Language methods
|
||||
//- (NSString*)getPlayVideoPrompt:(id)theWidget;
|
||||
//- (NSString*)getBackButtonPrompt:(id)theWidget isInterstitial:(BOOL)isInterstitial;
|
||||
//- (NSString*)getSafariButtonPrompt:(id)theWidget;
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
|
||||
AdWhirlAdapterMdotM.h
|
||||
|
||||
Copyright 2009 AdMob, Inc.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
*/
|
||||
|
||||
#import "AdWhirlAdNetworkAdapter.h"
|
||||
#import "AdWhirlCustomAdView.h"
|
||||
#import "AdWhirlWebBrowserController.h"
|
||||
|
||||
@interface AdWhirlAdapterMdotM : AdWhirlAdNetworkAdapter <AdWhirlCustomAdViewDelegate, AdWhirlWebBrowserControllerDelegate> {
|
||||
BOOL requesting;
|
||||
CLLocationManager *locationManager;
|
||||
NSURLConnection *adConnection;
|
||||
NSMutableData *adData;
|
||||
NSURLConnection *imageConnection;
|
||||
NSMutableData *imageData;
|
||||
AdWhirlCustomAdView *adView;
|
||||
AdWhirlWebBrowserController *webBrowserController;
|
||||
}
|
||||
|
||||
+ (AdWhirlAdNetworkType)networkType;
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,423 @@
|
||||
/*
|
||||
|
||||
AdWhirlAdapterMdotM.m
|
||||
|
||||
Copyright 2009 AdMob, Inc.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
*/
|
||||
|
||||
#import "AdWhirlAdapterMdotM.h"
|
||||
#import "AdWhirlView.h"
|
||||
#import "AdWhirlConfig.h"
|
||||
#import "AdWhirlAdNetworkConfig.h"
|
||||
#import "AdWhirlDelegateProtocol.h"
|
||||
#import "AdWhirlLog.h"
|
||||
#import "AdWhirlAdNetworkAdapter+Helpers.h"
|
||||
#import "AdWhirlAdNetworkRegistry.h"
|
||||
#import "AdWhirlAdapterCustom.h"
|
||||
#import "AdWhirlError.h"
|
||||
#import "CJSONDeserializer.h"
|
||||
#import "AdWhirlCustomAdView.h"
|
||||
|
||||
|
||||
@interface AdWhirlAdapterMdotM ()
|
||||
|
||||
- (BOOL)parseAdData:(NSData *)data error:(NSError **)error;
|
||||
|
||||
@property (nonatomic,readonly) CLLocationManager *locationManager;
|
||||
@property (nonatomic,retain) NSURLConnection *adConnection;
|
||||
@property (nonatomic,retain) NSURLConnection *imageConnection;
|
||||
@property (nonatomic,retain) AdWhirlCustomAdView *adView;
|
||||
@property (nonatomic,retain) AdWhirlWebBrowserController *webBrowserController;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@implementation AdWhirlAdapterMdotM
|
||||
|
||||
@synthesize adConnection;
|
||||
@synthesize imageConnection;
|
||||
@synthesize adView;
|
||||
@synthesize webBrowserController;
|
||||
|
||||
|
||||
+ (AdWhirlAdNetworkType)networkType {
|
||||
return AdWhirlAdNetworkTypeMdotM;
|
||||
}
|
||||
|
||||
+ (void)load {
|
||||
[[AdWhirlAdNetworkRegistry sharedRegistry] registerClass:self];
|
||||
}
|
||||
|
||||
- (BOOL)useTestAd {
|
||||
if ([adWhirlDelegate respondsToSelector:@selector(adWhirlTestMode)])
|
||||
return [adWhirlDelegate adWhirlTestMode];
|
||||
return NO;
|
||||
}
|
||||
|
||||
|
||||
- (id)initWithAdWhirlDelegate:(id<AdWhirlDelegate>)delegate
|
||||
view:(AdWhirlView *)view
|
||||
config:(AdWhirlConfig *)config
|
||||
networkConfig:(AdWhirlAdNetworkConfig *)netConf {
|
||||
self = [super initWithAdWhirlDelegate:delegate
|
||||
view:view
|
||||
config:config
|
||||
networkConfig:netConf];
|
||||
if (self != nil) {
|
||||
adData = [[NSMutableData alloc] init];
|
||||
imageData = [[NSMutableData alloc] init];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (NSMutableString *)appendUserContextDic:(NSDictionary *)dic withUrl:(NSString *)sUrl {
|
||||
NSArray *keyArray = [dic allKeys];
|
||||
NSMutableString *str = [NSMutableString stringWithString:sUrl];
|
||||
|
||||
//Iterate over the context disctionary and for each kay-value pair create a string of the format &key=value
|
||||
for (int i = 0; i < [keyArray count]; i++) {
|
||||
[str appendFormat:@"&%@=%@",[keyArray objectAtIndex:i], [dic objectForKey:[keyArray objectAtIndex:i]]];
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
|
||||
- (void)getAd {
|
||||
@synchronized(self) {
|
||||
if (requesting) return;
|
||||
requesting = YES;
|
||||
}
|
||||
|
||||
NSString *appKey = networkConfig.pubId;
|
||||
|
||||
if ([adWhirlDelegate respondsToSelector:@selector(MdotMApplicationKey)] ) {
|
||||
appKey = [adWhirlDelegate MdotMApplicationKey];
|
||||
}
|
||||
|
||||
UIDevice *device = [UIDevice currentDevice];
|
||||
NSBundle *bundle = [NSBundle mainBundle];
|
||||
NSLocale *locale = [NSLocale currentLocale];
|
||||
NSString *userAgent = [NSString stringWithFormat:@"%@ %@ (%@; %@ %@; %@)",
|
||||
[bundle objectForInfoDictionaryKey:@"CFBundleDisplayName"],
|
||||
[bundle objectForInfoDictionaryKey:@"CFBundleVersion"],
|
||||
[device model],
|
||||
[device systemName], [device systemVersion],
|
||||
[locale localeIdentifier]];
|
||||
int test;
|
||||
if ( [self useTestAd] ) {
|
||||
test = 1;
|
||||
} else
|
||||
test = 0;
|
||||
|
||||
NSString *str = [NSString stringWithFormat:
|
||||
@"http://ads.mdotm.com/ads/feed.php?appver=%d&v=%@&apikey=mdotm&appkey=%@&deviceid=%@&width=320&height=50&fmt=json&ua=%@&test=%d",
|
||||
kAdWhirlAppVer, [[UIDevice currentDevice] systemVersion],
|
||||
appKey, [[UIDevice currentDevice] uniqueIdentifier], userAgent, test];
|
||||
|
||||
NSMutableDictionary *userContextDic = [[NSMutableDictionary alloc] initWithCapacity:2];
|
||||
if ( [userContextDic count] > 0 ) {
|
||||
str = [self appendUserContextDic:userContextDic withUrl:str];
|
||||
}
|
||||
|
||||
NSString *urlString = [str stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
|
||||
|
||||
NSURL *adRequestURL = [[NSURL alloc] initWithString:urlString];
|
||||
AWLogDebug(@"Requesting MdotM ad (%@) %@", str, adRequestURL);
|
||||
NSURLRequest *adRequest = [NSURLRequest requestWithURL:adRequestURL];
|
||||
|
||||
|
||||
NSURLConnection *conn = [[NSURLConnection alloc] initWithRequest:adRequest
|
||||
delegate:self];
|
||||
self.adConnection = conn;
|
||||
[conn release];
|
||||
[adRequestURL release];
|
||||
[userContextDic release];
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
#pragma mark MdotMDelegate optional methods
|
||||
|
||||
- (BOOL)respondsToSelector:(SEL)selector {
|
||||
if (selector == @selector(location)
|
||||
&& ![adWhirlDelegate respondsToSelector:@selector(location)]) {
|
||||
return NO;
|
||||
}
|
||||
else if (selector == @selector(userContext)
|
||||
&& ![adWhirlDelegate respondsToSelector:@selector(userContext)]) {
|
||||
return NO;
|
||||
} return [super respondsToSelector:selector];
|
||||
}
|
||||
|
||||
|
||||
- (CLLocationManager *)locationManager {
|
||||
if (locationManager == nil) {
|
||||
locationManager = [[CLLocationManager alloc] init];
|
||||
}
|
||||
return locationManager;
|
||||
}
|
||||
|
||||
- (BOOL)parseEnums:(int *)val
|
||||
adInfo:(NSDictionary*)info
|
||||
minVal:(int)min
|
||||
maxVal:(int)max
|
||||
fieldName:(NSString *)name
|
||||
error:(NSError **)error {
|
||||
NSString *str = [info objectForKey:name];
|
||||
if (str == nil) {
|
||||
if (error != nil)
|
||||
*error = [AdWhirlError errorWithCode:AdWhirlCustomAdDataError
|
||||
description:[NSString stringWithFormat:
|
||||
@"MdotM ad data has no '%@' field", name]];
|
||||
return NO;
|
||||
}
|
||||
int intVal = [str intValue];
|
||||
if (intVal <= min || intVal >= max) {
|
||||
if (error != nil)
|
||||
*error = [AdWhirlError errorWithCode:AdWhirlCustomAdDataError
|
||||
description:[NSString stringWithFormat:
|
||||
@"MdotM ad data: Invalid value for %@ - %d", name, intVal]];
|
||||
return NO;
|
||||
}
|
||||
*val = intVal;
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (BOOL)parseAdData:(NSData *)data error:(NSError **)error {
|
||||
NSError *jsonError = nil;
|
||||
id parsed = [[CJSONDeserializer deserializer] deserialize:data error:&jsonError];
|
||||
if (parsed == nil) {
|
||||
if (error != nil)
|
||||
*error = [AdWhirlError errorWithCode:AdWhirlCustomAdParseError
|
||||
description:@"Error parsing MdotM ad JSON from server"
|
||||
underlyingError:jsonError];
|
||||
return NO;
|
||||
}
|
||||
if ([parsed isKindOfClass:[NSArray class]]) {
|
||||
NSArray *ads = parsed;
|
||||
NSDictionary *adInfo = nil;
|
||||
if ( [ads count] == 0 ) {
|
||||
return(NO);
|
||||
} else {
|
||||
id parsed0 =[ads objectAtIndex:0];
|
||||
if ( [parsed0 isKindOfClass:[NSDictionary class]] ) {
|
||||
adInfo = parsed0;
|
||||
|
||||
// gather up and validate ad info
|
||||
NSString *text = [adInfo objectForKey:@"ad_text"];
|
||||
NSString *redirectURLStr = [adInfo objectForKey:@"landing_url"];
|
||||
|
||||
int adTypeInt;
|
||||
if (![self parseEnums:&adTypeInt
|
||||
adInfo:adInfo
|
||||
minVal:AWCustomAdTypeMIN
|
||||
maxVal:AWCustomAdTypeMAX
|
||||
fieldName:@"ad_type"
|
||||
error:error]) {
|
||||
return NO;
|
||||
}
|
||||
AWCustomAdType adType = adTypeInt;
|
||||
|
||||
int launchTypeInt;
|
||||
if (![self parseEnums:&launchTypeInt
|
||||
adInfo:adInfo
|
||||
minVal:AWCustomAdLaunchTypeMIN
|
||||
maxVal:AWCustomAdLaunchTypeMAX
|
||||
fieldName:@"launch_type"
|
||||
error:error]) {
|
||||
return NO;
|
||||
}
|
||||
AWCustomAdLaunchType launchType = launchTypeInt;
|
||||
AWCustomAdWebViewAnimType animType = AWCustomAdWebViewAnimTypeCurlDown;
|
||||
|
||||
NSURL *redirectURL = nil;
|
||||
if (redirectURLStr == nil) {
|
||||
AWLogWarn(@"No redirect URL for MdotM ad");
|
||||
} else {
|
||||
redirectURL = [[NSURL alloc] initWithString:redirectURLStr];
|
||||
if (!redirectURL)
|
||||
AWLogWarn(@"MdotM ad: Malformed redirect URL string %@", redirectURLStr);
|
||||
}
|
||||
AWLogDebug(@"Got MdotM ad %@ %@ %d %d %d", text, redirectURL,
|
||||
adType, launchType, animType);
|
||||
|
||||
self.adView = [[AdWhirlCustomAdView alloc] initWithDelegate:self
|
||||
text:text
|
||||
redirectURL:redirectURL
|
||||
clickMetricsURL:nil
|
||||
adType:adType
|
||||
launchType:launchType
|
||||
animType:animType
|
||||
backgroundColor:[self helperBackgroundColorToUse]
|
||||
textColor:[self helperTextColorToUse]];
|
||||
[self.adView release];
|
||||
self.adNetworkView = adView;
|
||||
[redirectURL release];
|
||||
if (adView == nil) {
|
||||
if (error != nil)
|
||||
*error = [AdWhirlError errorWithCode:AdWhirlCustomAdDataError
|
||||
description:@"Error initializing MdotM ad view"];
|
||||
return NO;
|
||||
}
|
||||
|
||||
// fetch image
|
||||
id imageURL = [adInfo objectForKey:@"img_url"];
|
||||
if ( [imageURL isKindOfClass:[NSString class]]) {
|
||||
AWLogDebug(@"Request MdotM ad image at %@", imageURL);
|
||||
NSURLRequest *imageRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:imageURL]];
|
||||
NSURLConnection *conn = [[NSURLConnection alloc] initWithRequest:imageRequest
|
||||
delegate:self];
|
||||
self.imageConnection = conn;
|
||||
[conn release];
|
||||
} else {
|
||||
return(NO);
|
||||
}
|
||||
} else {
|
||||
return(NO);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (error != nil)
|
||||
*error = [AdWhirlError errorWithCode:AdWhirlCustomAdDataError
|
||||
description:@"Expected top-level dictionary in MdotM ad data"];
|
||||
return NO;
|
||||
}
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (void)stopBeingDelegate {
|
||||
AdWhirlCustomAdView *theAdView = (AdWhirlCustomAdView *)self.adNetworkView;
|
||||
if (theAdView != nil) {
|
||||
theAdView.delegate = nil;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)dealloc {
|
||||
[locationManager release], locationManager = nil;
|
||||
[adConnection release], adConnection = nil;
|
||||
[adData release], adData = nil;
|
||||
[imageConnection release], imageConnection = nil;
|
||||
[imageData release], imageData = nil;
|
||||
[adView release], adView = nil;
|
||||
[webBrowserController release], webBrowserController = nil;
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
#pragma mark NSURLConnection delegate methods.
|
||||
|
||||
- (void)connection:(NSURLConnection *)conn didReceiveResponse:(NSURLResponse *)response {
|
||||
if (conn == adConnection) {
|
||||
[adData setLength:0];
|
||||
}
|
||||
else if (conn == imageConnection) {
|
||||
[imageData setLength:0];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)connection:(NSURLConnection *)conn didFailWithError:(NSError *)error {
|
||||
if (conn == adConnection) {
|
||||
[adWhirlView adapter:self didFailAd:[AdWhirlError errorWithCode:AdWhirlCustomAdConnectionError
|
||||
description:@"Error connecting to MdotM ad server"
|
||||
underlyingError:error]];
|
||||
requesting = NO;
|
||||
} else if (conn == imageConnection) {
|
||||
[adWhirlView adapter:self didFailAd:[AdWhirlError errorWithCode:AdWhirlCustomAdConnectionError
|
||||
description:@"Error connecting to MdotM to fetch image"
|
||||
underlyingError:error]];
|
||||
requesting = NO;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)connectionDidFinishLoading:(NSURLConnection *)conn {
|
||||
if (conn == adConnection) {
|
||||
NSError *error = nil;
|
||||
if (![self parseAdData:adData error:&error]) {
|
||||
[adWhirlView adapter:self didFailAd:error];
|
||||
requesting = NO;
|
||||
return;
|
||||
}
|
||||
}
|
||||
else if (conn == imageConnection) {
|
||||
UIImage *image = [[UIImage alloc] initWithData:imageData];
|
||||
if (image == nil) {
|
||||
[adWhirlView adapter:self
|
||||
didFailAd:[AdWhirlError errorWithCode:AdWhirlCustomAdImageError
|
||||
description:@"Cannot initialize MdotM ad image from data"]];
|
||||
requesting = NO;
|
||||
return;
|
||||
}
|
||||
adView.image = image;
|
||||
[adView setNeedsDisplay];
|
||||
[image release];
|
||||
requesting = NO;
|
||||
[adWhirlView adapter:self didReceiveAdView:self.adView];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)connection:(NSURLConnection *)conn didReceiveData:(NSData *)data {
|
||||
if (conn == adConnection) {
|
||||
[adData appendData:data];
|
||||
}
|
||||
else if (conn == imageConnection) {
|
||||
[imageData appendData:data];
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark AdWhirlCustomAdViewDelegate methods
|
||||
|
||||
- (void)adTapped:(AdWhirlCustomAdView *)ad {
|
||||
if (ad != adView) return;
|
||||
if (ad.clickMetricsURL != nil) {
|
||||
NSURLRequest *metRequest = [NSURLRequest requestWithURL:ad.clickMetricsURL];
|
||||
[NSURLConnection connectionWithRequest:metRequest
|
||||
delegate:nil]; // fire and forget
|
||||
}
|
||||
if (ad.redirectURL == nil) {
|
||||
AWLogError(@"MdotM ad redirect URL is nil");
|
||||
return;
|
||||
}
|
||||
switch (ad.launchType) {
|
||||
case AWCustomAdLaunchTypeSafari:
|
||||
[[UIApplication sharedApplication] openURL:ad.redirectURL];
|
||||
break;
|
||||
case AWCustomAdLaunchTypeCanvas:
|
||||
if (self.webBrowserController == nil) {
|
||||
AdWhirlWebBrowserController *ctrlr = [[AdWhirlWebBrowserController alloc] init];
|
||||
self.webBrowserController = ctrlr;
|
||||
[ctrlr release];
|
||||
}
|
||||
webBrowserController.delegate = self;
|
||||
[webBrowserController presentWithController:[adWhirlDelegate viewControllerForPresentingModalView]
|
||||
transition:ad.animType];
|
||||
[self helperNotifyDelegateOfFullScreenModal];
|
||||
[webBrowserController loadURL:ad.redirectURL];
|
||||
break;
|
||||
default:
|
||||
AWLogError(@"MdotM ad: Unsupported launch type %d", ad.launchType);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark AdWhirlWebBrowserControllerDelegate methods
|
||||
|
||||
- (void)webBrowserClosed:(AdWhirlWebBrowserController *)controller {
|
||||
if (controller != webBrowserController) return;
|
||||
self.webBrowserController = nil; // don't keep around to save memory
|
||||
[self helperNotifyDelegateOfFullScreenModalDismissal];
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
|
||||
AdWhirlAdapterMillennial.h
|
||||
|
||||
Copyright 2009 AdMob, Inc.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
*/
|
||||
|
||||
#import "AdWhirlAdNetworkAdapter.h"
|
||||
#import "MMAdView.h"
|
||||
|
||||
@interface AdWhirlAdapterMillennial : AdWhirlAdNetworkAdapter <MMAdDelegate> {
|
||||
NSMutableDictionary *requestData;
|
||||
}
|
||||
|
||||
+ (AdWhirlAdNetworkType)networkType;
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,227 @@
|
||||
/*
|
||||
|
||||
AdWhirlAdapterMillennial.m
|
||||
|
||||
Copyright 2009 AdMob, Inc.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
*/
|
||||
|
||||
#import "AdWhirlAdapterMillennial.h"
|
||||
#import "AdWhirlView.h"
|
||||
#import "AdWhirlConfig.h"
|
||||
#import "AdWhirlAdNetworkConfig.h"
|
||||
#import "AdWhirlDelegateProtocol.h"
|
||||
#import "AdWhirlLog.h"
|
||||
#import "AdWhirlAdNetworkAdapter+Helpers.h"
|
||||
#import "AdWhirlAdNetworkRegistry.h"
|
||||
|
||||
#define kMillennialAdFrame (CGRectMake(0, 0, 320, 53))
|
||||
|
||||
@interface AdWhirlAdapterMillennial ()
|
||||
|
||||
- (CLLocationDegrees)latitude;
|
||||
|
||||
- (CLLocationDegrees)longitude;
|
||||
|
||||
- (NSInteger)age;
|
||||
|
||||
- (NSString *)zipCode;
|
||||
|
||||
- (NSString *)sex;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@implementation AdWhirlAdapterMillennial
|
||||
|
||||
+ (AdWhirlAdNetworkType)networkType {
|
||||
return AdWhirlAdNetworkTypeMillennial;
|
||||
}
|
||||
|
||||
+ (void)load {
|
||||
[[AdWhirlAdNetworkRegistry sharedRegistry] registerClass:self];
|
||||
}
|
||||
|
||||
- (void)getAd {
|
||||
NSString *apID;
|
||||
if ([adWhirlDelegate respondsToSelector:@selector(millennialMediaApIDString)]) {
|
||||
apID = [adWhirlDelegate millennialMediaApIDString];
|
||||
}
|
||||
else {
|
||||
apID = networkConfig.pubId;
|
||||
}
|
||||
|
||||
requestData = [[NSMutableDictionary alloc] initWithObjectsAndKeys:
|
||||
@"adwhirl", @"vendor",
|
||||
nil];
|
||||
if ([self respondsToSelector:@selector(zipCode)]) {
|
||||
[requestData setValue:[self zipCode] forKey:@"zip"];
|
||||
}
|
||||
if ([self respondsToSelector:@selector(age)]) {
|
||||
[requestData setValue:[NSString stringWithFormat:@"%d",[self age]] forKey:@"age"];
|
||||
}
|
||||
if ([self respondsToSelector:@selector(sex)]) {
|
||||
[requestData setValue:[self sex] forKey:@"sex"];
|
||||
}
|
||||
if ([self respondsToSelector:@selector(latitude)]) {
|
||||
[requestData setValue:[NSString stringWithFormat:@"%lf",[self latitude]] forKey:@"lat"];
|
||||
}
|
||||
if ([self respondsToSelector:@selector(longitude)]) {
|
||||
[requestData setValue:[NSString stringWithFormat:@"%lf",[self longitude]] forKey:@"long"];
|
||||
}
|
||||
MMAdType adType = MMBannerAdTop;
|
||||
if ([adWhirlDelegate respondsToSelector:@selector(millennialMediaAdType)]) {
|
||||
adType = [adWhirlDelegate millennialMediaAdType];
|
||||
}
|
||||
MMAdView *adView = [MMAdView adWithFrame:kMillennialAdFrame
|
||||
type:adType
|
||||
apid:apID
|
||||
delegate:self
|
||||
loadAd:YES
|
||||
startTimer:NO];
|
||||
self.adNetworkView = adView;
|
||||
}
|
||||
|
||||
- (void)stopBeingDelegate {
|
||||
MMAdView *adView = (MMAdView *)adNetworkView;
|
||||
if (adView != nil) {
|
||||
[adView setRefreshTimerEnabled:false];
|
||||
adView.delegate = nil;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)dealloc {
|
||||
[requestData release];
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
#pragma mark MMAdDelegate methods
|
||||
|
||||
- (NSDictionary *)requestData {
|
||||
AWLogDebug(@"Sending requestData to MM: %@", requestData);
|
||||
return requestData;
|
||||
}
|
||||
|
||||
- (void)adRequestSucceeded:(MMAdView *)adView {
|
||||
// millennial ads are slightly taller than default frame, at 53 pixels.
|
||||
[adWhirlView adapter:self didReceiveAdView:adNetworkView];
|
||||
}
|
||||
|
||||
- (void)adRequestFailed:(MMAdView *)adView {
|
||||
[adWhirlView adapter:self didFailAd:nil];
|
||||
}
|
||||
|
||||
- (void)adModalWillAppear {
|
||||
[self helperNotifyDelegateOfFullScreenModal];
|
||||
}
|
||||
|
||||
- (void)adModalWasDismissed {
|
||||
[self helperNotifyDelegateOfFullScreenModalDismissal];
|
||||
}
|
||||
|
||||
#pragma mark requestData optional methods
|
||||
|
||||
// The follow is kept for gathering requestData
|
||||
|
||||
- (BOOL)respondsToSelector:(SEL)selector {
|
||||
if (selector == @selector(latitude)
|
||||
&& ![adWhirlDelegate respondsToSelector:@selector(locationInfo)]) {
|
||||
return NO;
|
||||
}
|
||||
else if (selector == @selector(longitude)
|
||||
&& ![adWhirlDelegate respondsToSelector:@selector(locationInfo)]) {
|
||||
return NO;
|
||||
}
|
||||
else if (selector == @selector(age)
|
||||
&& (!([adWhirlDelegate respondsToSelector:@selector(millennialMediaAge)]
|
||||
|| [adWhirlDelegate respondsToSelector:@selector(dateOfBirth)])
|
||||
|| [self age] < 0)) {
|
||||
return NO;
|
||||
}
|
||||
else if (selector == @selector(zipCode)
|
||||
&& ![adWhirlDelegate respondsToSelector:@selector(postalCode)]) {
|
||||
return NO;
|
||||
}
|
||||
else if (selector == @selector(sex)
|
||||
&& ![adWhirlDelegate respondsToSelector:@selector(gender)]) {
|
||||
return NO;
|
||||
}
|
||||
else if (selector == @selector(householdIncome)
|
||||
&& ![adWhirlDelegate respondsToSelector:@selector(incomeLevel)]) {
|
||||
return NO;
|
||||
}
|
||||
else if (selector == @selector(educationLevel)
|
||||
&& ![adWhirlDelegate respondsToSelector:@selector(millennialMediaEducationLevel)]) {
|
||||
return NO;
|
||||
}
|
||||
else if (selector == @selector(ethnicity)
|
||||
&& ![adWhirlDelegate respondsToSelector:@selector(millennialMediaEthnicity)]) {
|
||||
return NO;
|
||||
}
|
||||
return [super respondsToSelector:selector];
|
||||
}
|
||||
|
||||
- (CLLocationDegrees)latitude {
|
||||
CLLocation *loc = [adWhirlDelegate locationInfo];
|
||||
if (loc == nil) return 0.0;
|
||||
return loc.coordinate.latitude;
|
||||
}
|
||||
|
||||
- (CLLocationDegrees)longitude {
|
||||
CLLocation *loc = [adWhirlDelegate locationInfo];
|
||||
if (loc == nil) return 0.0;
|
||||
return loc.coordinate.longitude;
|
||||
}
|
||||
|
||||
- (NSInteger)age {
|
||||
if ([adWhirlDelegate respondsToSelector:@selector(millennialMediaAge)]) {
|
||||
return [adWhirlDelegate millennialMediaAge];
|
||||
}
|
||||
return [self helperCalculateAge];
|
||||
}
|
||||
|
||||
- (NSString *)zipCode {
|
||||
return [adWhirlDelegate postalCode];
|
||||
}
|
||||
|
||||
- (NSString *)sex {
|
||||
NSString *gender = [adWhirlDelegate gender];
|
||||
NSString *sex = @"";
|
||||
if (gender == nil)
|
||||
return sex;
|
||||
if ([gender compare:@"m"] == NSOrderedSame) {
|
||||
sex = @"M";
|
||||
}
|
||||
else if ([gender compare:@"f"] == NSOrderedSame) {
|
||||
sex = @"F";
|
||||
}
|
||||
return sex;
|
||||
}
|
||||
|
||||
/*
|
||||
- (NSInteger)householdIncome {
|
||||
return (NSInteger)[adWhirlDelegate incomeLevel];
|
||||
}
|
||||
|
||||
- (MMEducation)educationLevel {
|
||||
return [adWhirlDelegate millennialMediaEducationLevel];
|
||||
}
|
||||
|
||||
- (MMEthnicity)ethnicity {
|
||||
return [adWhirlDelegate millennialMediaEthnicity];
|
||||
}
|
||||
*/
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
|
||||
AdWhirlAdapterNexage.h
|
||||
Copyright 2011 Google, Inc.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
*/
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "AdWhirlAdNetworkAdapter.h"
|
||||
#import "NexageDelegateProtocol.h"
|
||||
|
||||
@class NexageAdViewController;
|
||||
|
||||
@interface AdWhirlAdapterNexage : AdWhirlAdNetworkAdapter
|
||||
<NexageDelegateProtocol> {
|
||||
NexageAdViewController* adViewController;
|
||||
NSString* position;
|
||||
}
|
||||
|
||||
+ (AdWhirlAdNetworkType)networkType;
|
||||
- (NSDate *)dateOfBirth;
|
||||
- (NSString *)postCode;
|
||||
- (NSString *)gender;
|
||||
- (NSString *)keywords;
|
||||
- (NSInteger)houseIncome;
|
||||
- (NSString *)city;
|
||||
- (NSString *)designatedMarketArea;
|
||||
- (NSString *)country;
|
||||
- (NSString *)ethnicity;
|
||||
- (NSString *)maritalStatus;
|
||||
- (NSString *)areaCode;
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,219 @@
|
||||
/*
|
||||
|
||||
AdWhirlAdapterNexage.m
|
||||
Copyright 2011 Google, Inc.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
*/
|
||||
|
||||
#import "AdWhirlAdapterNexage.h"
|
||||
#import "AdWhirlAdNetworkAdapter+Helpers.h"
|
||||
#import "AdWhirlAdNetworkRegistry.h"
|
||||
#import "AdWhirlView.h"
|
||||
#import "AdWhirlConfig.h"
|
||||
#import "NexageAdViewController.h"
|
||||
#import "NexageAdParameters.h"
|
||||
#import "AdWhirlAdNetworkConfig.h"
|
||||
#import "AdWhirlError.h"
|
||||
|
||||
@implementation AdWhirlAdapterNexage
|
||||
|
||||
+ (AdWhirlAdNetworkType)networkType {
|
||||
return AdWhirlAdNetworkTypeNexage;
|
||||
}
|
||||
|
||||
+ (void)load {
|
||||
[[AdWhirlAdNetworkRegistry sharedRegistry] registerClass:self];
|
||||
}
|
||||
|
||||
- (void)getAd{
|
||||
NSDictionary* atts = [NSDictionary dictionaryWithObjectsAndKeys:
|
||||
[self dateOfBirth], @"u(dob)",
|
||||
[self country], @"u(country)",
|
||||
[self city], @"u(city)",
|
||||
[self designatedMarketArea], @"u(dma)",
|
||||
[self ethnicity], @"u(eth)",
|
||||
[self gender], @"u(gender)",
|
||||
[NSNumber numberWithDouble:[self houseIncome]], @"u(hhi)",
|
||||
[self keywords], @"u(keywords)",
|
||||
[self maritalStatus], @"u(marital)",
|
||||
[self postCode], @"u(zip)",
|
||||
nil];
|
||||
|
||||
NSDictionary* credDict;
|
||||
if ([adWhirlDelegate respondsToSelector:@selector(nexageDictionary)]) {
|
||||
credDict = [adWhirlDelegate nexageDictionary];
|
||||
}
|
||||
else {
|
||||
credDict = [networkConfig credentials];
|
||||
}
|
||||
|
||||
BOOL testMode = NO;
|
||||
if ([adWhirlDelegate respondsToSelector:@selector(adWhirlTestMode)]
|
||||
&& [adWhirlDelegate adWhirlTestMode]) {
|
||||
testMode = YES;
|
||||
}
|
||||
|
||||
// Nexage does weird things with position which can result in an over-release,
|
||||
// so we're basically forced to leak this...
|
||||
position = [[credDict objectForKey:@"position"] copy];
|
||||
if(position == nil){
|
||||
[adWhirlView adapter:self didFailAd:nil];
|
||||
return;
|
||||
}
|
||||
|
||||
adViewController =
|
||||
[[NexageAdViewController alloc] initWithDelegate:position delegate:self];
|
||||
[adViewController setEnable:YES];
|
||||
|
||||
|
||||
[adViewController setAttributes:atts];
|
||||
[adViewController setTestMode:testMode];
|
||||
[adViewController locationAware:adWhirlConfig.locationOn];
|
||||
#ifdef ADWHIRL_DEBUG
|
||||
[adViewController enableLogging:YES];
|
||||
#endif
|
||||
self.adNetworkView = adViewController.view;
|
||||
}
|
||||
|
||||
- (void)stopBeingDelegate {
|
||||
if (adViewController != nil) {
|
||||
adViewController.delegate = nil;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)dealloc {
|
||||
[self stopBeingDelegate];
|
||||
[adViewController setAttributes:nil];
|
||||
[adViewController release];
|
||||
adViewController = nil;
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
#pragma mark NexageDelegateProtocol
|
||||
|
||||
- (void)adReceived:(UIView *)ad {
|
||||
[adWhirlView adapter:self didReceiveAdView:ad];
|
||||
}
|
||||
/**
|
||||
* This method will be called when user clicks the ad banner.
|
||||
* The URL is an optional parameter, if Ad is from the Nexage mediation
|
||||
* platform, you will get validate url, if it is nil, that means the action
|
||||
* is from integrated sdk. Please check if (url == nil). The return YES, means
|
||||
* the sdk will handle click event, otherwise sdk will ignore the user action.
|
||||
* Basic Ad network principle should always return YES. Please refer our dev
|
||||
* document for details
|
||||
*/
|
||||
- (BOOL)adActionShouldBegin:(NSURLRequest *)request
|
||||
willLeaveApplication:(BOOL)willLeave {
|
||||
[self helperNotifyDelegateOfFullScreenModal];
|
||||
return YES;
|
||||
}
|
||||
|
||||
/**
|
||||
* The delegate will be called when full screen web browser is closed
|
||||
*/
|
||||
- (void)adFullScreenWebBrowserWillClose {
|
||||
[self helperNotifyDelegateOfFullScreenModalDismissal];
|
||||
}
|
||||
/**
|
||||
* identify the ad did not receive at this momnent.
|
||||
*/
|
||||
- (void)didFailToReceiveAd {
|
||||
[adWhirlView adapter:self didFailAd:nil];
|
||||
}
|
||||
|
||||
- (NSString *)dcnForAd {
|
||||
NSDictionary *credDict;
|
||||
if ([adWhirlDelegate respondsToSelector:@selector(nexageDictionary)]) {
|
||||
credDict = [adWhirlDelegate nexageDictionary];
|
||||
}
|
||||
else {
|
||||
credDict = [networkConfig credentials];
|
||||
}
|
||||
return [credDict objectForKey:@"dcn"];
|
||||
}
|
||||
|
||||
- (UIViewController*)currentViewController {
|
||||
return [adWhirlDelegate viewControllerForPresentingModalView];
|
||||
}
|
||||
|
||||
#pragma mark user profiles
|
||||
|
||||
- (NSDate *)dateOfBirth {
|
||||
if([adWhirlDelegate respondsToSelector:@selector(dateOfBirth)])
|
||||
return [adWhirlDelegate dateOfBirth];
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (NSString *)postCode {
|
||||
if([adWhirlDelegate respondsToSelector:@selector(postalCode)])
|
||||
return [adWhirlDelegate postalCode];
|
||||
else return nil;
|
||||
}
|
||||
|
||||
- (NSString *)gender {
|
||||
if([adWhirlDelegate respondsToSelector:@selector(gender)])
|
||||
return [adWhirlDelegate gender];
|
||||
else return nil;
|
||||
}
|
||||
|
||||
- (NSString *)keywords {
|
||||
if([adWhirlDelegate respondsToSelector:@selector(keywords)])
|
||||
return [adWhirlDelegate keywords];
|
||||
else return nil;
|
||||
}
|
||||
|
||||
- (NSInteger)houseIncome {
|
||||
if([adWhirlDelegate respondsToSelector:@selector(incomeLevel)])
|
||||
return [adWhirlDelegate incomeLevel];
|
||||
return 0;
|
||||
}
|
||||
|
||||
- (NSString *)city {
|
||||
if([adWhirlDelegate respondsToSelector:@selector(nexageCity)])
|
||||
return [adWhirlDelegate nexageCity];
|
||||
else return nil;
|
||||
}
|
||||
|
||||
- (NSString *)designatedMarketArea {
|
||||
if([adWhirlDelegate respondsToSelector:@selector(nexageDesignatedMarketArea)])
|
||||
return [adWhirlDelegate nexageDesignatedMarketArea];
|
||||
else return nil;
|
||||
}
|
||||
|
||||
- (NSString *)country {
|
||||
if([adWhirlDelegate respondsToSelector:@selector(nexageCountry)])
|
||||
return [adWhirlDelegate nexageCountry];
|
||||
else return nil;
|
||||
}
|
||||
|
||||
- (NSString *)ethnicity {
|
||||
if([adWhirlDelegate respondsToSelector:@selector(nexageEthnicity)])
|
||||
return [adWhirlDelegate nexageEthnicity];
|
||||
else return nil;
|
||||
}
|
||||
|
||||
- (NSString *)maritalStatus {
|
||||
if([adWhirlDelegate respondsToSelector:@selector(nexageMaritalStatus)])
|
||||
return [adWhirlDelegate nexageMaritalStatus];
|
||||
else return nil;
|
||||
}
|
||||
|
||||
- (NSString *)areaCode {
|
||||
if([adWhirlDelegate respondsToSelector:@selector(areaCode)])
|
||||
return [adWhirlDelegate areaCode];
|
||||
else return nil;
|
||||
}
|
||||
@end
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
|
||||
AdWhirlAdapterOneRiot.h
|
||||
|
||||
Copyright 2010 OneRiot, Inc.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
*/
|
||||
|
||||
#import "AdWhirlAdNetworkAdapter.h"
|
||||
#import "OneRiotAd.h"
|
||||
|
||||
@interface AdWhirlAdapterOneRiot : AdWhirlAdNetworkAdapter {
|
||||
OneRiotAd *adControl;
|
||||
}
|
||||
|
||||
+ (AdWhirlAdNetworkType)networkType;
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
|
||||
AdWhirlAdapterOneRiot.m
|
||||
|
||||
Copyright 2010 OneRiot, Inc.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
*/
|
||||
|
||||
#import "AdWhirlAdapterOneRiot.h"
|
||||
#import "AdWhirlAdNetworkRegistry.h"
|
||||
#import "AdWhirlAdNetworkAdapter+Helpers.h"
|
||||
#import "AdWhirlAdNetworkConfig.h"
|
||||
|
||||
@interface AdWhirlAdapterOneRiot ()
|
||||
|
||||
@property (nonatomic,retain) OneRiotAd *adControl;
|
||||
|
||||
@end
|
||||
|
||||
@implementation AdWhirlAdapterOneRiot
|
||||
|
||||
@synthesize adControl;
|
||||
|
||||
+ (AdWhirlAdNetworkType)networkType {
|
||||
return AdWhirlAdNetworkTypeOneRiot;
|
||||
}
|
||||
|
||||
+ (void)load {
|
||||
[[AdWhirlAdNetworkRegistry sharedRegistry] registerClass:self];
|
||||
}
|
||||
|
||||
- (void)getAd {
|
||||
NSString *appId = networkConfig.pubId;
|
||||
|
||||
if ([adWhirlDelegate respondsToSelector:@selector(oneRiotAppID)]) {
|
||||
appId = [adWhirlDelegate oneRiotAppID];
|
||||
}
|
||||
|
||||
adControl = [[OneRiotAd alloc] initWithAppId:appId andWidth:300
|
||||
andHeight:50];
|
||||
|
||||
adControl.RefreshInterval = adWhirlConfig.refreshInterval;
|
||||
adControl.ReportGPS = adWhirlConfig.locationOn;
|
||||
|
||||
if ([adWhirlDelegate
|
||||
respondsToSelector:@selector(oneRiotContextParameters)]) {
|
||||
NSArray* contextParams = [adWhirlDelegate oneRiotContextParameters];
|
||||
|
||||
for (NSString* param in contextParams){
|
||||
[adControl addContextParameters:param];
|
||||
}
|
||||
}
|
||||
[adControl loadAd];
|
||||
self.adNetworkView = adControl;
|
||||
}
|
||||
|
||||
-(void) dealloc {
|
||||
[adControl release];
|
||||
adControl = nil;
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
|
||||
AdWhirlAdapterQuattro.h
|
||||
|
||||
Copyright 2009 AdMob, Inc.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
*/
|
||||
|
||||
#import "AdWhirlAdNetworkAdapter.h"
|
||||
#import "QWAdView.h"
|
||||
|
||||
@interface AdWhirlAdapterQuattro : AdWhirlAdNetworkAdapter <QWAdViewDelegate> {
|
||||
|
||||
}
|
||||
|
||||
+ (AdWhirlAdNetworkType)networkType;
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,222 @@
|
||||
/*
|
||||
|
||||
AdWhirlAdapterQuattro.m
|
||||
|
||||
Copyright 2009 AdMob, Inc.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
*/
|
||||
|
||||
#import "AdWhirlAdapterQuattro.h"
|
||||
#import "AdWhirlView.h"
|
||||
#import "AdWhirlConfig.h"
|
||||
#import "AdWhirlAdNetworkConfig.h"
|
||||
#import "QWAdView.h"
|
||||
#import "QWTestMode.h"
|
||||
#import "AdWhirlLog.h"
|
||||
#import "AdWhirlAdNetworkAdapter+Helpers.h"
|
||||
#import "AdWhirlAdNetworkRegistry.h"
|
||||
|
||||
@implementation AdWhirlAdapterQuattro
|
||||
|
||||
+ (AdWhirlAdNetworkType)networkType {
|
||||
return AdWhirlAdNetworkTypeQuattro;
|
||||
}
|
||||
|
||||
+ (void)load {
|
||||
[[AdWhirlAdNetworkRegistry sharedRegistry] registerClass:self];
|
||||
}
|
||||
|
||||
- (void)getAd {
|
||||
QWEnableLocationServicesForAds(adWhirlConfig.locationOn);
|
||||
|
||||
if ([adWhirlDelegate respondsToSelector:@selector(adWhirlTestMode)]
|
||||
&& [adWhirlDelegate adWhirlTestMode]) {
|
||||
QWSetTestMode(YES);
|
||||
QWSetLogging(YES);
|
||||
}
|
||||
else {
|
||||
QWSetTestMode(NO);
|
||||
QWSetLogging(NO);
|
||||
}
|
||||
NSDictionary *credDict;
|
||||
if ([adWhirlDelegate respondsToSelector:@selector(quattroWirelessDictionary)]) {
|
||||
credDict = [adWhirlDelegate quattroWirelessDictionary];
|
||||
}
|
||||
else {
|
||||
credDict = [networkConfig credentials];
|
||||
}
|
||||
NSString *pubId = [credDict objectForKey:@"publisherID"];
|
||||
NSString *siteId = [credDict objectForKey:@"siteID"];
|
||||
QWAdType adType = QWAdTypeBanner;
|
||||
if ([adWhirlDelegate respondsToSelector:@selector(quattroWirelessAdType)]) {
|
||||
adType = (QWAdType)[adWhirlDelegate quattroWirelessAdType];
|
||||
}
|
||||
UIDeviceOrientation orientation;
|
||||
if ([self.adWhirlDelegate respondsToSelector:@selector(adWhirlCurrentOrientation)]) {
|
||||
orientation = [self.adWhirlDelegate adWhirlCurrentOrientation];
|
||||
}
|
||||
else {
|
||||
orientation = [UIDevice currentDevice].orientation;
|
||||
}
|
||||
QWAdView *quattroAd = [QWAdView adViewWithType:adType
|
||||
publisherID:pubId
|
||||
siteID:siteId
|
||||
orientation:orientation
|
||||
delegate:self];
|
||||
quattroAd.textColor = [self helperTextColorToUse];
|
||||
quattroAd.backgroundColor = [self helperBackgroundColorToUse];
|
||||
[quattroAd displayNewAd];
|
||||
self.adNetworkView = quattroAd;
|
||||
}
|
||||
|
||||
- (void)stopBeingDelegate {
|
||||
QWAdView *quattroAd = (QWAdView *)self.adNetworkView;
|
||||
if (quattroAd != nil) {
|
||||
quattroAd.delegate = nil;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)dealloc {
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
#pragma mark QWAdViewDelegate methods
|
||||
|
||||
- (void)adView:(QWAdView *)adView didDisplayAd:(QWAd *)ad {
|
||||
// somehow the test banner ad is showing 80 pixels as height sometimes.
|
||||
// check for that and adjust
|
||||
AWLogDebug(@"Quattro reported frame %@", NSStringFromCGRect(self.adNetworkView.frame));
|
||||
if (self.adNetworkView.frame.size.height > 50.0) {
|
||||
CGRect f = adNetworkView.frame;
|
||||
f.size.height = 50;
|
||||
adNetworkView.frame = f;
|
||||
}
|
||||
[adWhirlView adapter:self didReceiveAdView:adView];
|
||||
}
|
||||
|
||||
- (void)dispatchError:(NSError*)error
|
||||
{
|
||||
[adWhirlView adapter:self didFailAd:error];
|
||||
}
|
||||
|
||||
- (void)adView:(QWAdView *)adView failedWithError:(NSError *)error {
|
||||
[self performSelectorOnMainThread:@selector(dispatchError:) withObject:error waitUntilDone:NO];
|
||||
}
|
||||
|
||||
- (void)adView:(QWAdView *)adView displayLandingPage:(UIViewController *)controller {
|
||||
[self helperNotifyDelegateOfFullScreenModal];
|
||||
[[adWhirlDelegate viewControllerForPresentingModalView] presentModalViewController:controller
|
||||
animated:YES];
|
||||
}
|
||||
|
||||
- (void)adView:(QWAdView *)adView dismiss:(UIViewController *)controller {
|
||||
[[adWhirlDelegate viewControllerForPresentingModalView] dismissModalViewControllerAnimated:YES];
|
||||
[self helperNotifyDelegateOfFullScreenModalDismissal];
|
||||
}
|
||||
|
||||
#pragma mark QWAdViewDelegate optional methods
|
||||
|
||||
- (BOOL)respondsToSelector:(SEL)selector {
|
||||
if (selector == @selector(latitude:)
|
||||
&& ![adWhirlDelegate respondsToSelector:@selector(locationInfo)]) {
|
||||
return NO;
|
||||
}
|
||||
else if (selector == @selector(longitude:)
|
||||
&& ![adWhirlDelegate respondsToSelector:@selector(locationInfo)]) {
|
||||
return NO;
|
||||
}
|
||||
else if (selector == @selector(age:)
|
||||
&& (![adWhirlDelegate respondsToSelector:@selector(dateOfBirth)]
|
||||
|| [self age:nil] < 0)) {
|
||||
return NO;
|
||||
}
|
||||
else if (selector == @selector(zipcode:)
|
||||
&& ![adWhirlDelegate respondsToSelector:@selector(postalCode)]) {
|
||||
return NO;
|
||||
}
|
||||
else if (selector == @selector(gender:)
|
||||
&& ![adWhirlDelegate respondsToSelector:@selector(gender)]) {
|
||||
return NO;
|
||||
}
|
||||
else if (selector == @selector(income:)
|
||||
&& ![adWhirlDelegate respondsToSelector:@selector(incomeLevel)]) {
|
||||
return NO;
|
||||
}
|
||||
else if (selector == @selector(education:)
|
||||
&& ![adWhirlDelegate respondsToSelector:@selector(quattroWirelessEducationLevel)]) {
|
||||
return NO;
|
||||
}
|
||||
else if (selector == @selector(birthdate:)
|
||||
&& ![adWhirlDelegate respondsToSelector:@selector(dateOfBirth)]) {
|
||||
return NO;
|
||||
}
|
||||
else if (selector == @selector(ethnicity:)
|
||||
&& ![adWhirlDelegate respondsToSelector:@selector(quattroWirelessEthnicity)]) {
|
||||
return NO;
|
||||
}
|
||||
return [super respondsToSelector:selector];
|
||||
}
|
||||
|
||||
- (double)latitude:(QWAdView *)adView {
|
||||
CLLocation *loc = [adWhirlDelegate locationInfo];
|
||||
if (loc == nil) return 0.0;
|
||||
return loc.coordinate.latitude;
|
||||
}
|
||||
|
||||
- (double)longitude:(QWAdView *)adView {
|
||||
CLLocation *loc = [adWhirlDelegate locationInfo];
|
||||
if (loc == nil) return 0.0;
|
||||
return loc.coordinate.longitude;
|
||||
}
|
||||
|
||||
- (NSString *)zipcode:(QWAdView *)adView {
|
||||
return [adWhirlDelegate postalCode];
|
||||
}
|
||||
|
||||
- (NSUInteger)age:(QWAdView *)adView {
|
||||
return [self helperCalculateAge];
|
||||
}
|
||||
|
||||
- (QWGender)gender:(QWAdView *)adView {
|
||||
NSString *gender = [adWhirlDelegate gender];
|
||||
QWGender sex = QWGenderUnknown;
|
||||
if (gender == nil)
|
||||
return sex;
|
||||
if ([gender compare:@"m"] == NSOrderedSame) {
|
||||
sex = QWGenderMale;
|
||||
}
|
||||
else if ([gender compare:@"f"] == NSOrderedSame) {
|
||||
sex = QWGenderFemale;
|
||||
}
|
||||
return sex;
|
||||
}
|
||||
|
||||
- (NSUInteger)income:(QWAdView *)adView {
|
||||
return [adWhirlDelegate incomeLevel];
|
||||
}
|
||||
|
||||
- (QWEducationLevel)education:(QWAdView *)adView {
|
||||
return [adWhirlDelegate quattroWirelessEducationLevel];
|
||||
}
|
||||
|
||||
- (NSDate *)birthdate:(QWAdView *)adView {
|
||||
return [adWhirlDelegate dateOfBirth];
|
||||
}
|
||||
|
||||
- (QWEthnicity)ethnicity:(QWAdView *)adView {
|
||||
return [adWhirlDelegate quattroWirelessEthnicity];
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
|
||||
AdWhirlAdapterVideoEgg.h
|
||||
|
||||
Copyright 2009 AdMob, Inc.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
*/
|
||||
|
||||
#import "AdWhirlAdNetworkAdapter.h"
|
||||
|
||||
@interface AdWhirlAdapterVideoEgg : AdWhirlAdNetworkAdapter {
|
||||
|
||||
}
|
||||
|
||||
+ (AdWhirlAdNetworkType)networkType;
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,117 @@
|
||||
/*
|
||||
|
||||
AdWhirlAdapterVideoEgg.m
|
||||
|
||||
Copyright 2009 AdMob, Inc.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
*/
|
||||
|
||||
#import "AdWhirlAdapterVideoEgg.h"
|
||||
#import "AdWhirlView.h"
|
||||
#import "AdWhirlConfig.h"
|
||||
#import "AdWhirlAdNetworkConfig.h"
|
||||
#import "AdFrameView.h"
|
||||
#import "AdWhirlLog.h"
|
||||
#import "AdWhirlAdNetworkAdapter+Helpers.h"
|
||||
#import "AdWhirlAdNetworkRegistry.h"
|
||||
|
||||
@interface AdWhirlAdapterVideoEgg ()
|
||||
|
||||
- (void)loadSuccess:(NSNotification *)notification;
|
||||
- (void)loadFailed:(NSNotification *)notification;
|
||||
- (void)launchAd:(NSNotification *)notification;
|
||||
- (void)closeAd:(NSNotification *)notification;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@implementation AdWhirlAdapterVideoEgg
|
||||
|
||||
+ (AdWhirlAdNetworkType)networkType {
|
||||
return AdWhirlAdNetworkTypeVideoEgg;
|
||||
}
|
||||
|
||||
+ (void)load {
|
||||
[[AdWhirlAdNetworkRegistry sharedRegistry] registerClass:self];
|
||||
}
|
||||
|
||||
- (void)getAd {
|
||||
AdFrameView *aw = [[AdFrameView alloc] init];
|
||||
|
||||
NSDictionary *credentials = [networkConfig credentials];
|
||||
if ([adWhirlDelegate respondsToSelector:@selector(adWhirlTestMode)]
|
||||
&& [adWhirlDelegate adWhirlTestMode]) {
|
||||
credentials = [NSDictionary dictionaryWithObjectsAndKeys:
|
||||
@"testpublisher", @"publisher",
|
||||
@"testarea", @"area",
|
||||
nil];
|
||||
}
|
||||
else if ([adWhirlDelegate respondsToSelector:@selector(videoEggConfigDictionary)]) {
|
||||
credentials = [adWhirlDelegate videoEggConfigDictionary];
|
||||
}
|
||||
|
||||
NSNotificationCenter *notifCenter = [NSNotificationCenter defaultCenter];
|
||||
[notifCenter addObserver:self
|
||||
selector:@selector(loadSuccess:)
|
||||
name:kVELoadSuccess
|
||||
object:aw];
|
||||
[notifCenter addObserver:self
|
||||
selector:@selector(loadFailed:)
|
||||
name:kVELoadFailure
|
||||
object:aw];
|
||||
[notifCenter addObserver:self
|
||||
selector:@selector(launchAd:)
|
||||
name:kVELaunchedAd
|
||||
object:aw];
|
||||
[notifCenter addObserver:self
|
||||
selector:@selector(closeAd:)
|
||||
name:kVEClosedAd
|
||||
object:aw];
|
||||
|
||||
VEConfig *config = [VEConfig dictionaryWithDictionary:credentials];
|
||||
[aw requestAd:config];
|
||||
self.adNetworkView = aw;
|
||||
[aw release];
|
||||
}
|
||||
|
||||
- (void)stopBeingDelegate {
|
||||
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
||||
}
|
||||
|
||||
- (void)dealloc {
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
#pragma mark VideoEgg notification methods
|
||||
|
||||
- (void)loadSuccess:(NSNotification *)notification {
|
||||
CGRect frame = CGRectMake(0,0,ADFRAME_BANNER_WIDTH, ADFRAME_BANNER_HEIGHT);
|
||||
adNetworkView.frame = frame;
|
||||
[adWhirlView adapter:self didReceiveAdView:adNetworkView];
|
||||
}
|
||||
|
||||
- (void)loadFailed:(NSNotification *)notification {
|
||||
[adWhirlView adapter:self didFailAd:nil];
|
||||
}
|
||||
|
||||
- (void)launchAd:(NSNotification *)notification {
|
||||
[self helperNotifyDelegateOfFullScreenModal];
|
||||
}
|
||||
|
||||
- (void)closeAd:(NSNotification *)notification {
|
||||
[self helperNotifyDelegateOfFullScreenModalDismissal];
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
|
||||
AdWhirlAdapterZestADZ.h
|
||||
|
||||
Copyright 2009 AdMob, Inc.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
*/
|
||||
|
||||
#import "AdWhirlAdNetworkAdapter.h"
|
||||
#import "ZestadzDelegateProtocal.h"
|
||||
|
||||
@class ZestadzView;
|
||||
|
||||
@interface AdWhirlAdapterZestADZ : AdWhirlAdNetworkAdapter <ZestadzDelegate> {
|
||||
|
||||
}
|
||||
|
||||
+ (AdWhirlAdNetworkType)networkType;
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,101 @@
|
||||
/*
|
||||
|
||||
AdWhirlAdapterZestADZ.m
|
||||
|
||||
Copyright 2009 AdMob, Inc.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
*/
|
||||
|
||||
#import "AdWhirlAdapterZestADZ.h"
|
||||
#import "AdWhirlAdNetworkConfig.h"
|
||||
#import "AdWhirlView.h"
|
||||
#import "ZestadzView.h"
|
||||
#import "AdWhirlLog.h"
|
||||
#import "AdWhirlAdNetworkAdapter+Helpers.h"
|
||||
#import "AdWhirlAdNetworkRegistry.h"
|
||||
|
||||
@implementation AdWhirlAdapterZestADZ
|
||||
|
||||
+ (AdWhirlAdNetworkType)networkType {
|
||||
return AdWhirlAdNetworkTypeZestADZ;
|
||||
}
|
||||
|
||||
+ (void)load {
|
||||
[[AdWhirlAdNetworkRegistry sharedRegistry] registerClass:self];
|
||||
}
|
||||
|
||||
- (void)getAd {
|
||||
ZestadzView *zestView = [ZestadzView requestAdWithDelegate:self];
|
||||
self.adNetworkView = zestView;
|
||||
}
|
||||
|
||||
- (void)stopBeingDelegate {
|
||||
// no way to set zestView's delegate to nil
|
||||
}
|
||||
|
||||
- (void)dealloc {
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
#pragma mark ZestadzDelegate required methods.
|
||||
|
||||
- (NSString *)clientId {
|
||||
if ([adWhirlDelegate respondsToSelector:@selector(zestADZClientID)]) {
|
||||
return [adWhirlDelegate zestADZClientID];
|
||||
}
|
||||
return networkConfig.pubId;
|
||||
}
|
||||
|
||||
- (UIViewController *)currentViewController {
|
||||
return [adWhirlDelegate viewControllerForPresentingModalView];
|
||||
}
|
||||
|
||||
#pragma mark ZestadzDelegate notification methods
|
||||
|
||||
- (void)didReceiveAd:(ZestadzView *)adView {
|
||||
[adWhirlView adapter:self didReceiveAdView:adView];
|
||||
}
|
||||
|
||||
- (void)didFailToReceiveAd:(ZestadzView *)adView {
|
||||
[adWhirlView adapter:self didFailAd:nil];
|
||||
}
|
||||
|
||||
- (void)willPresentFullScreenModal {
|
||||
[self helperNotifyDelegateOfFullScreenModal];
|
||||
}
|
||||
|
||||
- (void)didDismissFullScreenModal {
|
||||
[self helperNotifyDelegateOfFullScreenModalDismissal];
|
||||
}
|
||||
|
||||
#pragma mark ZestadzDelegate config methods
|
||||
- (UIColor *)adBackgroundColor {
|
||||
if ([adWhirlDelegate respondsToSelector:@selector(adWhirlAdBackgroundColor)]) {
|
||||
return [adWhirlDelegate adWhirlAdBackgroundColor];
|
||||
}
|
||||
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (NSString *)keywords {
|
||||
if ([adWhirlDelegate respondsToSelector:@selector(keywords)]) {
|
||||
return [adWhirlDelegate keywords];
|
||||
}
|
||||
|
||||
return @"iphone ipad ipod";
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
Reference in New Issue
Block a user