adding adNetwork SDKs for AdWhirl and AdMob
This commit is contained in:
+30
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
|
||||
AdWhirlSDK2_SampleAppDelegate.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.
|
||||
|
||||
*/
|
||||
|
||||
@interface AdWhirlSDK2_SampleAppDelegate : NSObject <UIApplicationDelegate> {
|
||||
UIWindow *window;
|
||||
UINavigationController *navigationController;
|
||||
}
|
||||
|
||||
@property (nonatomic, retain) IBOutlet UIWindow *window;
|
||||
@property (nonatomic, retain) IBOutlet UINavigationController *navigationController;
|
||||
|
||||
@end
|
||||
|
||||
+59
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
|
||||
AdWhirlSDK2_SampleAppDelegate.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 "AdWhirlSDK2_SampleAppDelegate.h"
|
||||
#import "RootViewController.h"
|
||||
#import "AdWhirlLog.h"
|
||||
|
||||
@implementation AdWhirlSDK2_SampleAppDelegate
|
||||
|
||||
@synthesize window;
|
||||
@synthesize navigationController;
|
||||
|
||||
|
||||
#pragma mark -
|
||||
#pragma mark Application lifecycle
|
||||
|
||||
- (void)applicationDidFinishLaunching:(UIApplication *)application {
|
||||
#ifdef ADWHIRL_DEBUG
|
||||
AWLogSetLogLevel(AWLogLevelDebug);
|
||||
#endif
|
||||
[window addSubview:[navigationController view]];
|
||||
[window makeKeyAndVisible];
|
||||
}
|
||||
|
||||
|
||||
- (void)applicationWillTerminate:(UIApplication *)application {
|
||||
// Save data if appropriate
|
||||
}
|
||||
|
||||
|
||||
#pragma mark -
|
||||
#pragma mark Memory management
|
||||
|
||||
- (void)dealloc {
|
||||
[navigationController release];
|
||||
[window release];
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
|
||||
@end
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
//
|
||||
// BottomBannerController.h
|
||||
// AdWhirlSDK2_Sample
|
||||
//
|
||||
// Created by Nigel Choi on 1/26/10.
|
||||
// Copyright 2010 Admob. Inc.. All rights reserved.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
#import "SimpleViewController.h"
|
||||
|
||||
@interface BottomBannerController : SimpleViewController {
|
||||
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,116 @@
|
||||
//
|
||||
// BottomBannerController.m
|
||||
// AdWhirlSDK2_Sample
|
||||
//
|
||||
// Created by Nigel Choi on 1/26/10.
|
||||
// Copyright 2010 Admob. Inc.. All rights reserved.
|
||||
//
|
||||
|
||||
#import "BottomBannerController.h"
|
||||
#import "AdWhirlView.h"
|
||||
|
||||
#define BOTBVIEW_BUTTON_1_TAG 607701
|
||||
#define BOTBVIEW_BUTTON_2_TAG 607702
|
||||
#define BOTBVIEW_BUTTON_1_OFFSET 15
|
||||
#define BOTBVIEW_BUTTON_2_OFFSET 37
|
||||
#define BOTBVIEW_LABEL_OFFSET 67
|
||||
#define BOTBVIEW_LABEL_HDIFF 45
|
||||
|
||||
@implementation BottomBannerController
|
||||
|
||||
- (id)init {
|
||||
if (self = [super initWithNibName:@"BottomBannerController" bundle:nil]) {
|
||||
currLayoutOrientation = UIInterfaceOrientationPortrait; // nib file defines a portrait view
|
||||
self.title = @"Bottom Banner";
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)viewDidLoad {
|
||||
[super viewDidLoad];
|
||||
}
|
||||
|
||||
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
|
||||
duration:(NSTimeInterval)duration {
|
||||
[self adjustLayoutToOrientation:interfaceOrientation];
|
||||
}
|
||||
|
||||
- (void)adjustLayoutToOrientation:(UIInterfaceOrientation)newOrientation {
|
||||
if (UIInterfaceOrientationIsPortrait(currLayoutOrientation)
|
||||
&& UIInterfaceOrientationIsLandscape(newOrientation)) {
|
||||
UIView *button1 = [self.view viewWithTag:BOTBVIEW_BUTTON_1_TAG];
|
||||
UIView *button2 = [self.view viewWithTag:BOTBVIEW_BUTTON_2_TAG];
|
||||
assert(button1 != nil);
|
||||
assert(button2 != nil);
|
||||
CGPoint newCenter = button1.center;
|
||||
newCenter.y -= BOTBVIEW_BUTTON_1_OFFSET;
|
||||
button1.center = newCenter;
|
||||
newCenter = button2.center;
|
||||
newCenter.y -= BOTBVIEW_BUTTON_2_OFFSET;
|
||||
button2.center = newCenter;
|
||||
CGRect newFrame = self.label.frame;
|
||||
newFrame.size.height -= 45;
|
||||
newFrame.origin.y -= BOTBVIEW_LABEL_OFFSET;
|
||||
self.label.frame = newFrame;
|
||||
}
|
||||
else if (UIInterfaceOrientationIsLandscape(currLayoutOrientation)
|
||||
&& UIInterfaceOrientationIsPortrait(newOrientation)) {
|
||||
UIView *button1 = [self.view viewWithTag:BOTBVIEW_BUTTON_1_TAG];
|
||||
UIView *button2 = [self.view viewWithTag:BOTBVIEW_BUTTON_2_TAG];
|
||||
assert(button1 != nil);
|
||||
assert(button2 != nil);
|
||||
CGPoint newCenter = button1.center;
|
||||
newCenter.y += BOTBVIEW_BUTTON_1_OFFSET;
|
||||
button1.center = newCenter;
|
||||
newCenter = button2.center;
|
||||
newCenter.y += BOTBVIEW_BUTTON_2_OFFSET;
|
||||
button2.center = newCenter;
|
||||
CGRect newFrame = self.label.frame;
|
||||
newFrame.size.height += 45;
|
||||
newFrame.origin.y += BOTBVIEW_LABEL_OFFSET;
|
||||
self.label.frame = newFrame;
|
||||
}
|
||||
CGRect adFrame = [adView frame];
|
||||
CGRect screenBounds = [[UIScreen mainScreen] bounds];
|
||||
if (UIInterfaceOrientationIsPortrait(newOrientation)) {
|
||||
adFrame.origin.y = screenBounds.size.height
|
||||
- adFrame.size.height
|
||||
- self.navigationController.navigationBar.frame.size.height
|
||||
- [UIApplication sharedApplication].statusBarFrame.size.height;
|
||||
[adView setFrame:adFrame];
|
||||
}
|
||||
else if (UIInterfaceOrientationIsLandscape(newOrientation)) {
|
||||
adFrame.origin.y = screenBounds.size.width
|
||||
- adFrame.size.height
|
||||
- self.navigationController.navigationBar.frame.size.height
|
||||
- [UIApplication sharedApplication].statusBarFrame.size.width;
|
||||
[adView setFrame:adFrame];
|
||||
}
|
||||
currLayoutOrientation = newOrientation;
|
||||
}
|
||||
|
||||
- (void)adjustAdSize {
|
||||
[UIView beginAnimations:@"AdResize" context:nil];
|
||||
[UIView setAnimationDuration:0.7];
|
||||
CGSize adSize = [adView actualAdSize];
|
||||
CGRect newFrame = adView.frame;
|
||||
newFrame.size.height = adSize.height;
|
||||
newFrame.size.width = adSize.width;
|
||||
newFrame.origin.x = (self.view.bounds.size.width - adSize.width)/2;
|
||||
newFrame.origin.y = self.view.bounds.size.height - adSize.height;
|
||||
adView.frame = newFrame;
|
||||
[UIView commitAnimations];
|
||||
}
|
||||
|
||||
- (void)dealloc {
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
#pragma mark AdWhirlDelegate methods
|
||||
|
||||
- (NSUInteger)millennialMediaAdType {
|
||||
return 2;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
//
|
||||
// LocationController.h
|
||||
// AdWhirlSDK2_Sample
|
||||
//
|
||||
// Created by Nigel Choi on 2/8/10.
|
||||
// Copyright 2010 Admob. Inc.. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "TableController.h"
|
||||
|
||||
@interface LocationController : TableController <CLLocationManagerDelegate> {
|
||||
CLLocationManager *locationManager;
|
||||
UIInterfaceOrientation currLayoutOrientation;
|
||||
}
|
||||
|
||||
@property (nonatomic,readonly) UILabel *locLabel;
|
||||
|
||||
- (void)adjustLayoutToOrientation:(UIInterfaceOrientation)newOrientation;
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,104 @@
|
||||
//
|
||||
// LocationController.m
|
||||
// AdWhirlSDK2_Sample
|
||||
//
|
||||
// Created by Nigel Choi on 2/8/10.
|
||||
// Copyright 2010 Admob. Inc.. All rights reserved.
|
||||
//
|
||||
|
||||
#import "LocationController.h"
|
||||
#import "AdWhirlLog.h"
|
||||
|
||||
#define LOCVIEW_LOCLABEL_OFFSET 79
|
||||
#define LOCVIEW_LABEL_OFFSET 87
|
||||
#define LOCVIEW_LABEL_HDIFF 63
|
||||
|
||||
@implementation LocationController
|
||||
|
||||
- (id)init {
|
||||
if (self = [super initWithNibName:@"LocationController" bundle:nil]) {
|
||||
locationManager = [[CLLocationManager alloc] init];
|
||||
locationManager.delegate = self;
|
||||
[locationManager startUpdatingLocation];
|
||||
currLayoutOrientation = UIInterfaceOrientationPortrait; // nib file defines a portrait view
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)viewDidLoad {
|
||||
[super viewDidLoad];
|
||||
[self adjustLayoutToOrientation:self.interfaceOrientation];
|
||||
}
|
||||
|
||||
- (UILabel *)locLabel {
|
||||
return (UILabel *)[self.view viewWithTag:103];
|
||||
}
|
||||
|
||||
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
|
||||
duration:(NSTimeInterval)duration {
|
||||
[self adjustLayoutToOrientation:interfaceOrientation];
|
||||
}
|
||||
|
||||
- (void)adjustLayoutToOrientation:(UIInterfaceOrientation)newOrientation {
|
||||
UILabel *ll = self.locLabel;
|
||||
UILabel *label = self.label;
|
||||
assert(ll != nil);
|
||||
assert(label != nil);
|
||||
if (UIInterfaceOrientationIsPortrait(currLayoutOrientation)
|
||||
&& UIInterfaceOrientationIsLandscape(newOrientation)) {
|
||||
CGPoint newCenter = ll.center;
|
||||
newCenter.y -= LOCVIEW_LOCLABEL_OFFSET;
|
||||
ll.center = newCenter;
|
||||
CGRect newFrame = label.frame;
|
||||
newFrame.origin.y -= LOCVIEW_LABEL_OFFSET;
|
||||
newFrame.size.height -= LOCVIEW_LABEL_HDIFF;
|
||||
label.frame = newFrame;
|
||||
}
|
||||
else if (UIInterfaceOrientationIsLandscape(currLayoutOrientation)
|
||||
&& UIInterfaceOrientationIsPortrait(newOrientation)) {
|
||||
CGPoint newCenter = ll.center;
|
||||
newCenter.y += LOCVIEW_LOCLABEL_OFFSET;
|
||||
ll.center = newCenter;
|
||||
CGRect newFrame = label.frame;
|
||||
newFrame.origin.y += LOCVIEW_LABEL_OFFSET;
|
||||
newFrame.size.height += LOCVIEW_LABEL_HDIFF;
|
||||
label.frame = newFrame;
|
||||
}
|
||||
currLayoutOrientation = newOrientation;
|
||||
}
|
||||
|
||||
- (void)dealloc {
|
||||
locationManager.delegate = nil;
|
||||
[locationManager release], locationManager = nil;
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
|
||||
#pragma mark AdWhirlDelegate methods
|
||||
|
||||
- (CLLocation *)locationInfo {
|
||||
CLLocation *loc = [locationManager location];
|
||||
AWLogDebug(@"AdWhirl asking for location: %@", loc);
|
||||
return loc;
|
||||
}
|
||||
|
||||
|
||||
#pragma mark CLLocationManagerDelegate methods
|
||||
|
||||
- (void)locationManager:(CLLocationManager *)manager
|
||||
didFailWithError:(NSError *)error {
|
||||
[locationManager stopUpdatingLocation];
|
||||
self.locLabel.text = [NSString stringWithFormat:@"Error getting location: %@",
|
||||
[error localizedDescription]];
|
||||
AWLogError(@"Failed getting location: %@", error);
|
||||
}
|
||||
|
||||
- (void)locationManager:(CLLocationManager *)manager
|
||||
didUpdateToLocation:(CLLocation *)newLocation
|
||||
fromLocation:(CLLocation *)oldLocation {
|
||||
self.locLabel.text = [NSString stringWithFormat:@"%lf %lf",
|
||||
newLocation.coordinate.longitude,
|
||||
newLocation.coordinate.latitude];
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,18 @@
|
||||
//
|
||||
// ModalViewController.h
|
||||
// AdWhirlSDK2_Sample
|
||||
//
|
||||
// Created by Nigel Choi on 3/11/10.
|
||||
// Copyright 2010 Admob. Inc. All rights reserved.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
|
||||
@interface ModalViewController : UIViewController {
|
||||
|
||||
}
|
||||
|
||||
- (IBAction)dismiss:(id)sender;
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,68 @@
|
||||
//
|
||||
// ModalViewController.m
|
||||
// AdWhirlSDK2_Sample
|
||||
//
|
||||
// Created by Nigel Choi on 3/11/10.
|
||||
// Copyright 2010 Admob. Inc. All rights reserved.
|
||||
//
|
||||
|
||||
#import "ModalViewController.h"
|
||||
|
||||
|
||||
@implementation ModalViewController
|
||||
|
||||
- (id)init {
|
||||
if (self = [super initWithNibName:@"ModalViewController" bundle:nil]) {
|
||||
self.title = @"Modal View";
|
||||
if ([self respondsToSelector:@selector(setModalTransitionStyle)]) {
|
||||
[self setModalTransitionStyle:UIModalTransitionStyleCoverVertical];
|
||||
}
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
/*
|
||||
// The designated initializer. Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
|
||||
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
|
||||
if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) {
|
||||
// Custom initialization
|
||||
}
|
||||
return self;
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
|
||||
- (void)viewDidLoad {
|
||||
[super viewDidLoad];
|
||||
}
|
||||
*/
|
||||
|
||||
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (IBAction)dismiss:(id)sender {
|
||||
[self dismissModalViewControllerAnimated:YES];
|
||||
}
|
||||
|
||||
- (void)didReceiveMemoryWarning {
|
||||
// Releases the view if it doesn't have a superview.
|
||||
[super didReceiveMemoryWarning];
|
||||
|
||||
// Release any cached data, images, etc that aren't in use.
|
||||
}
|
||||
|
||||
- (void)viewDidUnload {
|
||||
[super viewDidUnload];
|
||||
// Release any retained subviews of the main view.
|
||||
// e.g. self.myOutlet = nil;
|
||||
}
|
||||
|
||||
|
||||
- (void)dealloc {
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
|
||||
RootViewController.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"
|
||||
|
||||
@interface RootViewController : UITableViewController <AdWhirlDelegate> {
|
||||
BOOL configFetched;
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,244 @@
|
||||
/*
|
||||
|
||||
RootViewController.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 "AdWhirlSDK2_SampleAppDelegate.h"
|
||||
#import "RootViewController.h"
|
||||
#import "SimpleViewController.h"
|
||||
#import "TableController.h"
|
||||
#import "BottomBannerController.h"
|
||||
#import "LocationController.h"
|
||||
#import "AdWhirlView.h"
|
||||
#import "SampleConstants.h"
|
||||
|
||||
#define CONFIG_PREFETCH_ROW 4
|
||||
|
||||
@implementation RootViewController
|
||||
|
||||
/*
|
||||
- (void)viewDidLoad {
|
||||
[super viewDidLoad];
|
||||
|
||||
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
|
||||
// self.navigationItem.rightBarButtonItem = self.editButtonItem;
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
- (void)viewWillAppear:(BOOL)animated {
|
||||
[super viewWillAppear:animated];
|
||||
}
|
||||
*/
|
||||
/*
|
||||
- (void)viewDidAppear:(BOOL)animated {
|
||||
[super viewDidAppear:animated];
|
||||
}
|
||||
*/
|
||||
/*
|
||||
- (void)viewWillDisappear:(BOOL)animated {
|
||||
[super viewWillDisappear:animated];
|
||||
}
|
||||
*/
|
||||
/*
|
||||
- (void)viewDidDisappear:(BOOL)animated {
|
||||
[super viewDidDisappear:animated];
|
||||
}
|
||||
*/
|
||||
|
||||
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (void)didReceiveMemoryWarning {
|
||||
// Releases the view if it doesn't have a superview.
|
||||
[super didReceiveMemoryWarning];
|
||||
|
||||
// Release any cached data, images, etc that aren't in use.
|
||||
}
|
||||
|
||||
- (void)viewDidUnload {
|
||||
// Release anything that can be recreated in viewDidLoad or on demand.
|
||||
// e.g. self.myOutlet = nil;
|
||||
}
|
||||
|
||||
|
||||
#pragma mark Table view methods
|
||||
|
||||
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
|
||||
return CONFIG_PREFETCH_ROW+1;
|
||||
}
|
||||
|
||||
|
||||
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
|
||||
|
||||
static NSString *CellIdentifier = @"Cell";
|
||||
|
||||
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
|
||||
if (cell == nil) {
|
||||
if ([UITableViewCell instancesRespondToSelector:@selector(initWithStyle:reuseIdentifier:)]) {
|
||||
// iPhone SDK 3.0
|
||||
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
|
||||
}
|
||||
else {
|
||||
// iPhone SDK 2.2.1
|
||||
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
|
||||
}
|
||||
}
|
||||
|
||||
switch (indexPath.row) {
|
||||
case 0:
|
||||
if ([cell respondsToSelector:@selector(textLabel)]) {
|
||||
// iPhone SDK 3.0
|
||||
cell.textLabel.text = @"Simple View";
|
||||
}
|
||||
else {
|
||||
// iPhone SDK 2.2.1
|
||||
cell.text = @"Simple View";
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
if ([cell respondsToSelector:@selector(textLabel)]) {
|
||||
// iPhone SDK 3.0
|
||||
cell.textLabel.text = @"Table Integration";
|
||||
}
|
||||
else {
|
||||
// iPhone SDK 2.2.1
|
||||
cell.text = @"Table Integration";
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
if ([cell respondsToSelector:@selector(textLabel)]) {
|
||||
// iPhone SDK 3.0
|
||||
cell.textLabel.text = @"Bottom Banner";
|
||||
}
|
||||
else {
|
||||
// iPhone SDK 2.2.1
|
||||
cell.text = @"Bottom Banner";
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
if ([cell respondsToSelector:@selector(textLabel)]) {
|
||||
// iPhone SDK 3.0
|
||||
cell.textLabel.text = @"Table w/ Location Info";
|
||||
}
|
||||
else {
|
||||
// iPhone SDK 2.2.1
|
||||
cell.text = @"Table w/ Location Info";
|
||||
}
|
||||
break;
|
||||
case CONFIG_PREFETCH_ROW:
|
||||
{
|
||||
NSString *configText;
|
||||
if (configFetched) {
|
||||
configText = @"Update Config";
|
||||
}
|
||||
else {
|
||||
configText = @"Prefetch Config";
|
||||
}
|
||||
if ([cell respondsToSelector:@selector(textLabel)]) {
|
||||
// iPhone SDK 3.0
|
||||
cell.textLabel.text = configText;
|
||||
}
|
||||
else {
|
||||
// iPhone SDK 2.2.1
|
||||
cell.text = configText;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return cell;
|
||||
}
|
||||
|
||||
|
||||
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
|
||||
switch (indexPath.row) {
|
||||
case 0:
|
||||
{
|
||||
SimpleViewController *simple = [[SimpleViewController alloc] init];
|
||||
[self.navigationController pushViewController:simple animated:YES];
|
||||
[simple release];
|
||||
break;
|
||||
}
|
||||
case 1:
|
||||
{
|
||||
TableController *table = [[TableController alloc] init];
|
||||
[self.navigationController pushViewController:table animated:YES];
|
||||
[table release];
|
||||
break;
|
||||
}
|
||||
case 2:
|
||||
{
|
||||
BottomBannerController *bbc = [[BottomBannerController alloc] init];
|
||||
[self.navigationController pushViewController:bbc animated:YES];
|
||||
[bbc release];
|
||||
break;
|
||||
}
|
||||
case 3:
|
||||
{
|
||||
LocationController *loc = [[LocationController alloc] init];
|
||||
[self.navigationController pushViewController:loc animated:YES];
|
||||
[loc release];
|
||||
break;
|
||||
}
|
||||
case CONFIG_PREFETCH_ROW:
|
||||
if (configFetched) {
|
||||
[AdWhirlView updateAdWhirlConfigWithDelegate:self];
|
||||
}
|
||||
else {
|
||||
[AdWhirlView startPreFetchingConfigurationDataWithDelegate:self];
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
- (void)dealloc {
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
|
||||
#pragma mark AdWhirlDelegate methods
|
||||
|
||||
- (NSString *)adWhirlApplicationKey {
|
||||
return kSampleAppKey;
|
||||
}
|
||||
|
||||
- (UIViewController *)viewControllerForPresentingModalView {
|
||||
return [((AdWhirlSDK2_SampleAppDelegate *)[[UIApplication sharedApplication] delegate]) navigationController];
|
||||
}
|
||||
|
||||
- (NSURL *)adWhirlConfigURL {
|
||||
return [NSURL URLWithString:kSampleConfigURL];
|
||||
}
|
||||
|
||||
- (void)adWhirlDidReceiveConfig:(AdWhirlView *)adWhirlView {
|
||||
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:CONFIG_PREFETCH_ROW inSection:0];
|
||||
[self.tableView deselectRowAtIndexPath:indexPath animated:YES];
|
||||
configFetched = YES;
|
||||
[self.tableView reloadData];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
|
||||
SampleConstants.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.
|
||||
|
||||
*/
|
||||
|
||||
#if !defined(kSampleAppKey)
|
||||
#error "You must define kSampleAppKey as your AdWhirl SDK Key"
|
||||
#endif
|
||||
|
||||
#define kSampleConfigURL @"http://mob.adwhirl.com/getInfo.php"
|
||||
#define kSampleImpMetricURL @"http://met.adwhirl.com/exmet.php"
|
||||
#define kSampleClickMetricURL @"http://met.adwhirl.com/exclick.php"
|
||||
#define kSampleCustomAdURL @"http://mob.adwhirl.com/custom.php"
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
|
||||
SimpleViewController.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 <UIKit/UIKit.h>
|
||||
#import "AdWhirlDelegateProtocol.h"
|
||||
|
||||
@class AdWhirlView;
|
||||
@interface SimpleViewController : UIViewController <AdWhirlDelegate> {
|
||||
AdWhirlView *adView;
|
||||
UIInterfaceOrientation currLayoutOrientation;
|
||||
}
|
||||
|
||||
- (IBAction)requestNewAd:(id)sender;
|
||||
- (IBAction)requestNewConfig:(id)sender;
|
||||
- (IBAction)rollOver:(id)sender;
|
||||
- (IBAction)showModalView:(id)sender;
|
||||
- (IBAction)toggleRefreshAd:(id)sender;
|
||||
- (void)adjustLayoutToOrientation:(UIInterfaceOrientation)newOrientation;
|
||||
- (void)adjustAdSize;
|
||||
|
||||
@property (nonatomic,retain) AdWhirlView *adView;
|
||||
@property (nonatomic,readonly) UILabel *label;
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,441 @@
|
||||
/*
|
||||
|
||||
SimpleViewController.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 "AdWhirlSDK2_SampleAppDelegate.h"
|
||||
#import "SimpleViewController.h"
|
||||
#import "AdWhirlView.h"
|
||||
#import "AdWhirlView+.h"
|
||||
#import "SampleConstants.h"
|
||||
#import "ModalViewController.h"
|
||||
#import "AdWhirlLog.h"
|
||||
|
||||
#define SIMPVIEW_BUTTON_1_TAG 607701
|
||||
#define SIMPVIEW_BUTTON_2_TAG 607702
|
||||
#define SIMPVIEW_BUTTON_3_TAG 607703
|
||||
#define SIMPVIEW_BUTTON_4_TAG 607704
|
||||
#define SIMPVIEW_SWITCH_1_TAG 706613
|
||||
#define SIMPVIEW_LABEL_1_TAG 7066130
|
||||
#define SIMPVIEW_BUTTON_1_OFFSET 46
|
||||
#define SIMPVIEW_BUTTON_2_OFFSET 46
|
||||
#define SIMPVIEW_BUTTON_3_OFFSET 66
|
||||
#define SIMPVIEW_BUTTON_4_OFFSET 86
|
||||
#define SIMPVIEW_SWITCH_1_OFFSET 69
|
||||
#define SIMPVIEW_LABEL_1_OFFSET 43
|
||||
#define SIMPVIEW_LABEL_1_OFFSETX 60
|
||||
#define SIMPVIEW_LABEL_OFFSET 94
|
||||
#define SIMPVIEW_LABEL_HDIFF 45
|
||||
|
||||
@implementation SimpleViewController
|
||||
|
||||
@synthesize adView;
|
||||
|
||||
- (id)init {
|
||||
if (self = [super initWithNibName:@"SimpleViewController" bundle:nil]) {
|
||||
currLayoutOrientation = UIInterfaceOrientationPortrait; // nib file defines a portrait view
|
||||
self.title = @"Simple View";
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)viewDidLoad {
|
||||
[super viewDidLoad];
|
||||
self.adView = [AdWhirlView requestAdWhirlViewWithDelegate:self];
|
||||
self.adView.autoresizingMask =
|
||||
UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleRightMargin;
|
||||
[self.view addSubview:self.adView];
|
||||
|
||||
if (getenv("ADWHIRL_FAKE_DARTS")) {
|
||||
// To make ad network selection deterministic
|
||||
const char *dartcstr = getenv("ADWHIRL_FAKE_DARTS");
|
||||
NSArray *rawdarts = [[NSString stringWithCString:dartcstr]
|
||||
componentsSeparatedByString:@" "];
|
||||
NSMutableArray *darts
|
||||
= [[NSMutableArray alloc] initWithCapacity:[rawdarts count]];
|
||||
for (NSString *dartstr in rawdarts) {
|
||||
if ([dartstr length] == 0) {
|
||||
continue;
|
||||
}
|
||||
[darts addObject:[NSNumber numberWithDouble:[dartstr doubleValue]]];
|
||||
}
|
||||
self.adView.testDarts = darts;
|
||||
}
|
||||
|
||||
UIDevice *device = [UIDevice currentDevice];
|
||||
if ([device respondsToSelector:@selector(isMultitaskingSupported)] &&
|
||||
[device isMultitaskingSupported]) {
|
||||
[[NSNotificationCenter defaultCenter]
|
||||
addObserver:self
|
||||
selector:@selector(enterForeground:)
|
||||
name:UIApplicationWillEnterForegroundNotification
|
||||
object:nil];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)viewWillAppear:(BOOL)animated {
|
||||
[super viewDidAppear:animated];
|
||||
[self adjustLayoutToOrientation:self.interfaceOrientation];
|
||||
}
|
||||
|
||||
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)io {
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
|
||||
duration:(NSTimeInterval)duration {
|
||||
[super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
|
||||
[self.adView rotateToOrientation:toInterfaceOrientation];
|
||||
[self adjustAdSize];
|
||||
}
|
||||
|
||||
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)io
|
||||
duration:(NSTimeInterval)duration {
|
||||
[self adjustLayoutToOrientation:io];
|
||||
}
|
||||
|
||||
- (void)adjustLayoutToOrientation:(UIInterfaceOrientation)newOrientation {
|
||||
UIView *button1 = [self.view viewWithTag:SIMPVIEW_BUTTON_1_TAG];
|
||||
UIView *button2 = [self.view viewWithTag:SIMPVIEW_BUTTON_2_TAG];
|
||||
UIView *button3 = [self.view viewWithTag:SIMPVIEW_BUTTON_3_TAG];
|
||||
UIView *button4 = [self.view viewWithTag:SIMPVIEW_BUTTON_4_TAG];
|
||||
UIView *switch1 = [self.view viewWithTag:SIMPVIEW_SWITCH_1_TAG];
|
||||
UIView *label1 = [self.view viewWithTag:SIMPVIEW_LABEL_1_TAG];
|
||||
assert(button1 != nil);
|
||||
assert(button2 != nil);
|
||||
assert(button3 != nil);
|
||||
assert(button4 != nil);
|
||||
assert(switch1 != nil);
|
||||
assert(label1 != nil);
|
||||
if (UIInterfaceOrientationIsPortrait(currLayoutOrientation)
|
||||
&& UIInterfaceOrientationIsLandscape(newOrientation)) {
|
||||
CGPoint newCenter = button1.center;
|
||||
newCenter.y -= SIMPVIEW_BUTTON_1_OFFSET;
|
||||
button1.center = newCenter;
|
||||
newCenter = button2.center;
|
||||
newCenter.y -= SIMPVIEW_BUTTON_2_OFFSET;
|
||||
button2.center = newCenter;
|
||||
newCenter = button3.center;
|
||||
newCenter.y -= SIMPVIEW_BUTTON_3_OFFSET;
|
||||
button3.center = newCenter;
|
||||
newCenter = button4.center;
|
||||
newCenter.y -= SIMPVIEW_BUTTON_4_OFFSET;
|
||||
button4.center = newCenter;
|
||||
newCenter = switch1.center;
|
||||
newCenter.y -= SIMPVIEW_SWITCH_1_OFFSET;
|
||||
switch1.center = newCenter;
|
||||
newCenter = label1.center;
|
||||
newCenter.y -= SIMPVIEW_LABEL_1_OFFSET;
|
||||
newCenter.x += SIMPVIEW_LABEL_1_OFFSETX;
|
||||
label1.center = newCenter;
|
||||
CGRect newFrame = self.label.frame;
|
||||
newFrame.size.height -= 45;
|
||||
newFrame.origin.y -= SIMPVIEW_LABEL_OFFSET;
|
||||
self.label.frame = newFrame;
|
||||
}
|
||||
else if (UIInterfaceOrientationIsLandscape(currLayoutOrientation)
|
||||
&& UIInterfaceOrientationIsPortrait(newOrientation)) {
|
||||
CGPoint newCenter = button1.center;
|
||||
newCenter.y += SIMPVIEW_BUTTON_1_OFFSET;
|
||||
button1.center = newCenter;
|
||||
newCenter = button2.center;
|
||||
newCenter.y += SIMPVIEW_BUTTON_2_OFFSET;
|
||||
button2.center = newCenter;
|
||||
newCenter = button3.center;
|
||||
newCenter.y += SIMPVIEW_BUTTON_3_OFFSET;
|
||||
button3.center = newCenter;
|
||||
newCenter = button4.center;
|
||||
newCenter.y += SIMPVIEW_BUTTON_4_OFFSET;
|
||||
button4.center = newCenter;
|
||||
newCenter = switch1.center;
|
||||
newCenter.y += SIMPVIEW_SWITCH_1_OFFSET;
|
||||
switch1.center = newCenter;
|
||||
newCenter = label1.center;
|
||||
newCenter.y += SIMPVIEW_LABEL_1_OFFSET;
|
||||
newCenter.x -= SIMPVIEW_LABEL_1_OFFSETX;
|
||||
label1.center = newCenter;
|
||||
CGRect newFrame = self.label.frame;
|
||||
newFrame.size.height += 45;
|
||||
newFrame.origin.y += SIMPVIEW_LABEL_OFFSET;
|
||||
self.label.frame = newFrame;
|
||||
}
|
||||
currLayoutOrientation = newOrientation;
|
||||
}
|
||||
|
||||
- (void)adjustAdSize {
|
||||
[UIView beginAnimations:@"AdResize" context:nil];
|
||||
[UIView setAnimationDuration:0.7];
|
||||
CGSize adSize = [adView actualAdSize];
|
||||
CGRect newFrame = adView.frame;
|
||||
newFrame.size.height = adSize.height;
|
||||
newFrame.size.width = adSize.width;
|
||||
newFrame.origin.x = (self.view.bounds.size.width - adSize.width)/2;
|
||||
adView.frame = newFrame;
|
||||
[UIView commitAnimations];
|
||||
}
|
||||
|
||||
- (void)didReceiveMemoryWarning {
|
||||
// Releases the view if it doesn't have a superview.
|
||||
[super didReceiveMemoryWarning];
|
||||
|
||||
// Release any cached data, images, etc that aren't in use.
|
||||
}
|
||||
|
||||
- (void)viewDidUnload {
|
||||
// remove all notification for self
|
||||
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
||||
}
|
||||
|
||||
- (UILabel *)label {
|
||||
return (UILabel *)[self.view viewWithTag:1337];
|
||||
}
|
||||
|
||||
- (void)dealloc {
|
||||
self.adView.delegate = nil;
|
||||
self.adView = nil;
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
#pragma mark Button handlers
|
||||
|
||||
- (IBAction)requestNewAd:(id)sender {
|
||||
self.label.text = @"Request New Ad pressed! Requesting...";
|
||||
[adView requestFreshAd];
|
||||
}
|
||||
|
||||
- (IBAction)requestNewConfig:(id)sender {
|
||||
self.label.text = @"Request New Config pressed! Requesting...";
|
||||
[adView updateAdWhirlConfig];
|
||||
}
|
||||
|
||||
- (IBAction)rollOver:(id)sender {
|
||||
self.label.text = @"Roll Over pressed! Requesting...";
|
||||
[adView rollOver];
|
||||
}
|
||||
|
||||
- (IBAction)showModalView:(id)sender {
|
||||
ModalViewController *modalViewController = [[[ModalViewController alloc] init] autorelease];
|
||||
[self presentModalViewController:modalViewController animated:YES];
|
||||
}
|
||||
|
||||
- (IBAction)toggleRefreshAd:(id)sender {
|
||||
UISwitch *switch1 = (UISwitch *)[self.view viewWithTag:SIMPVIEW_SWITCH_1_TAG];
|
||||
if (switch1.on) {
|
||||
[adView doNotIgnoreAutoRefreshTimer];
|
||||
}
|
||||
else {
|
||||
[adView ignoreAutoRefreshTimer];
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark AdWhirlDelegate methods
|
||||
|
||||
- (NSString *)adWhirlApplicationKey {
|
||||
return kSampleAppKey;
|
||||
}
|
||||
|
||||
- (UIViewController *)viewControllerForPresentingModalView {
|
||||
return [((AdWhirlSDK2_SampleAppDelegate *)[[UIApplication sharedApplication] delegate]) navigationController];
|
||||
}
|
||||
|
||||
- (NSURL *)adWhirlConfigURL {
|
||||
return [NSURL URLWithString:kSampleConfigURL];
|
||||
}
|
||||
|
||||
- (NSURL *)adWhirlImpMetricURL {
|
||||
return [NSURL URLWithString:kSampleImpMetricURL];
|
||||
}
|
||||
|
||||
- (NSURL *)adWhirlClickMetricURL {
|
||||
return [NSURL URLWithString:kSampleClickMetricURL];
|
||||
}
|
||||
|
||||
- (NSURL *)adWhirlCustomAdURL {
|
||||
return [NSURL URLWithString:kSampleCustomAdURL];
|
||||
}
|
||||
|
||||
- (void)adWhirlDidReceiveAd:(AdWhirlView *)adWhirlView {
|
||||
self.label.text = [NSString stringWithFormat:
|
||||
@"Got ad from %@, size %@",
|
||||
[adWhirlView mostRecentNetworkName],
|
||||
NSStringFromCGSize([adWhirlView actualAdSize])];
|
||||
[self adjustAdSize];
|
||||
}
|
||||
|
||||
- (void)adWhirlDidFailToReceiveAd:(AdWhirlView *)adWhirlView usingBackup:(BOOL)yesOrNo {
|
||||
self.label.text = [NSString stringWithFormat:
|
||||
@"Failed to receive ad from %@, %@. Error: %@",
|
||||
[adWhirlView mostRecentNetworkName],
|
||||
yesOrNo? @"will use backup" : @"will NOT use backup",
|
||||
adWhirlView.lastError == nil? @"no error" : [adWhirlView.lastError localizedDescription]];
|
||||
}
|
||||
|
||||
- (void)adWhirlReceivedRequestForDeveloperToFufill:(AdWhirlView *)adWhirlView {
|
||||
UILabel *replacement = [[UILabel alloc] initWithFrame:kAdWhirlViewDefaultFrame];
|
||||
replacement.backgroundColor = [UIColor redColor];
|
||||
replacement.textColor = [UIColor whiteColor];
|
||||
replacement.textAlignment = UITextAlignmentCenter;
|
||||
replacement.text = @"Generic Notification";
|
||||
[adWhirlView replaceBannerViewWith:replacement];
|
||||
[replacement release];
|
||||
[self adjustAdSize];
|
||||
self.label.text = @"Generic Notification";
|
||||
}
|
||||
|
||||
- (void)adWhirlReceivedNotificationAdsAreOff:(AdWhirlView *)adWhirlView {
|
||||
self.label.text = @"Ads are off";
|
||||
}
|
||||
|
||||
- (void)adWhirlWillPresentFullScreenModal {
|
||||
NSLog(@"SimpleView: will present full screen modal");
|
||||
}
|
||||
|
||||
- (void)adWhirlDidDismissFullScreenModal {
|
||||
NSLog(@"SimpleView: did dismiss full screen modal");
|
||||
}
|
||||
|
||||
- (void)adWhirlDidReceiveConfig:(AdWhirlView *)adWhirlView {
|
||||
self.label.text = @"Received config. Requesting ad...";
|
||||
}
|
||||
|
||||
- (BOOL)adWhirlTestMode {
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (UIColor *)adWhirlAdBackgroundColor {
|
||||
return [UIColor purpleColor];
|
||||
}
|
||||
|
||||
- (UIColor *)adWhirlTextColor {
|
||||
return [UIColor cyanColor];
|
||||
}
|
||||
|
||||
- (CLLocation *)locationInfo {
|
||||
CLLocationManager *locationManager = [[CLLocationManager alloc] init];
|
||||
CLLocation *location = [locationManager location];
|
||||
[locationManager release];
|
||||
return location;
|
||||
}
|
||||
|
||||
- (NSDate *)dateOfBirth {
|
||||
NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
|
||||
NSDateComponents *comps = [[NSDateComponents alloc] init];
|
||||
[comps setYear:1979];
|
||||
[comps setMonth:11];
|
||||
[comps setDay:6];
|
||||
NSDate *date = [gregorian dateFromComponents:comps];
|
||||
[gregorian release];
|
||||
[comps release];
|
||||
return date;
|
||||
}
|
||||
|
||||
- (NSString *)postalCode {
|
||||
return @"31337";
|
||||
}
|
||||
|
||||
- (NSUInteger)incomeLevel {
|
||||
return 99999;
|
||||
}
|
||||
|
||||
- (NSString *)googleAdSenseCompanyName {
|
||||
return @"Your Company";
|
||||
}
|
||||
|
||||
- (NSString *)googleAdSenseAppName {
|
||||
return @"AdWhirl Sample";
|
||||
}
|
||||
|
||||
- (NSString *)googleAdSenseApplicationAppleID {
|
||||
return @"0";
|
||||
}
|
||||
|
||||
- (NSString *)googleAdSenseKeywords {
|
||||
return @"iphone+development,ad+mediation";
|
||||
}
|
||||
|
||||
- (NSURL *)googleAdSenseAppWebContentURL {
|
||||
return [NSURL URLWithString:@"http://www.adwhirl.com"];
|
||||
}
|
||||
|
||||
- (NSArray *)googleAdSenseChannelIDs {
|
||||
return [NSArray arrayWithObjects:@"0282698142", nil];
|
||||
}
|
||||
|
||||
//extern NSString* const kGADAdSenseTextImageAdType;
|
||||
//- (NSString *)googleAdSenseAdType {
|
||||
// return kGADAdSenseTextImageAdType;
|
||||
//}
|
||||
|
||||
- (NSString *)googleAdSenseHostID {
|
||||
return @"HostID";
|
||||
}
|
||||
|
||||
- (UIColor *)googleAdSenseAdTopBackgroundColor {
|
||||
return [UIColor orangeColor];
|
||||
}
|
||||
|
||||
- (UIColor *)googleAdSenseAdBorderColor {
|
||||
return [UIColor redColor];
|
||||
}
|
||||
|
||||
- (UIColor *)googleAdSenseAdLinkColor {
|
||||
return [UIColor cyanColor];
|
||||
}
|
||||
|
||||
- (UIColor *)googleAdSenseAdURLColor {
|
||||
return [UIColor orangeColor];
|
||||
}
|
||||
|
||||
- (UIColor *)googleAdSenseAlternateAdColor {
|
||||
return [UIColor greenColor];
|
||||
}
|
||||
|
||||
- (NSURL *)googleAdSenseAlternateAdURL {
|
||||
return [NSURL URLWithString:@"http://www.adwhirl.com"];
|
||||
}
|
||||
|
||||
- (NSNumber *)googleAdSenseAllowAdsafeMedium {
|
||||
return [NSNumber numberWithBool:YES];
|
||||
}
|
||||
|
||||
#pragma mark event methods
|
||||
|
||||
- (void)performEvent {
|
||||
self.label.text = @"Event performed";
|
||||
}
|
||||
|
||||
- (void)performEvent2:(AdWhirlView *)adWhirlView {
|
||||
UILabel *replacement = [[UILabel alloc] initWithFrame:kAdWhirlViewDefaultFrame];
|
||||
replacement.backgroundColor = [UIColor blackColor];
|
||||
replacement.textColor = [UIColor whiteColor];
|
||||
replacement.textAlignment = UITextAlignmentCenter;
|
||||
replacement.text = [NSString stringWithFormat:@"Event performed, view %x", adWhirlView];
|
||||
[adWhirlView replaceBannerViewWith:replacement];
|
||||
[replacement release];
|
||||
[self adjustAdSize];
|
||||
self.label.text = [NSString stringWithFormat:@"Event performed, view %x", adWhirlView];
|
||||
}
|
||||
|
||||
#pragma mark multitasking methods
|
||||
|
||||
- (void)enterForeground:(NSNotification *)notification {
|
||||
AWLogDebug(@"SimpleView entering foreground");
|
||||
[self.adView updateAdWhirlConfig];
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
|
||||
TableController.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 <UIKit/UIKit.h>
|
||||
#import "AdWhirlDelegateProtocol.h"
|
||||
|
||||
@interface TableController : UIViewController <AdWhirlDelegate, UITableViewDelegate, UITableViewDataSource> {
|
||||
AdWhirlView *adView;
|
||||
}
|
||||
|
||||
@property (nonatomic,retain) AdWhirlView *adView;
|
||||
@property (nonatomic,readonly) UILabel *label;
|
||||
@property (nonatomic,readonly) UITableView *table;
|
||||
|
||||
- (void)adjustAdSize;
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,339 @@
|
||||
/*
|
||||
|
||||
TableController.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 "AdWhirlSDK2_SampleAppDelegate.h"
|
||||
#import "TableController.h"
|
||||
#import "AdWhirlView.h"
|
||||
#import "SampleConstants.h"
|
||||
|
||||
|
||||
@implementation TableController
|
||||
|
||||
@synthesize adView;
|
||||
|
||||
- (id)init {
|
||||
if (self = [super initWithNibName:@"TableController" bundle:nil]) {
|
||||
self.title = @"Ad In Table";
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)viewDidLoad {
|
||||
[super viewDidLoad];
|
||||
self.adView = [AdWhirlView requestAdWhirlViewWithDelegate:self];
|
||||
self.adView.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleRightMargin;
|
||||
}
|
||||
|
||||
/*
|
||||
- (void)viewWillAppear:(BOOL)animated {
|
||||
[super viewWillAppear:animated];
|
||||
}
|
||||
*/
|
||||
/*
|
||||
- (void)viewDidAppear:(BOOL)animated {
|
||||
[super viewDidAppear:animated];
|
||||
}
|
||||
*/
|
||||
/*
|
||||
- (void)viewWillDisappear:(BOOL)animated {
|
||||
[super viewWillDisappear:animated];
|
||||
}
|
||||
*/
|
||||
/*
|
||||
- (void)viewDidDisappear:(BOOL)animated {
|
||||
[super viewDidDisappear:animated];
|
||||
}
|
||||
*/
|
||||
|
||||
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
|
||||
duration:(NSTimeInterval)duration {
|
||||
[super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
|
||||
[self.adView rotateToOrientation:toInterfaceOrientation];
|
||||
[self adjustAdSize];
|
||||
}
|
||||
|
||||
- (void)didReceiveMemoryWarning {
|
||||
// Releases the view if it doesn't have a superview.
|
||||
[super didReceiveMemoryWarning];
|
||||
|
||||
// Release any cached data, images, etc that aren't in use.
|
||||
}
|
||||
|
||||
- (void)viewDidUnload {
|
||||
// Release any retained subviews of the main view.
|
||||
// e.g. self.myOutlet = nil;
|
||||
}
|
||||
|
||||
- (UILabel *)label {
|
||||
return (UILabel *)[self.view viewWithTag:1337];
|
||||
}
|
||||
|
||||
- (UITableView *)table {
|
||||
return (UITableView *)[self.view viewWithTag:3337];
|
||||
}
|
||||
|
||||
- (void)adjustAdSize {
|
||||
[UIView beginAnimations:@"AdResize" context:nil];
|
||||
[UIView setAnimationDuration:0.7];
|
||||
CGSize adSize = [adView actualAdSize];
|
||||
CGRect newFrame = adView.frame;
|
||||
newFrame.size.height = adSize.height;
|
||||
newFrame.size.width = adSize.width;
|
||||
newFrame.origin.x = (self.view.bounds.size.width - adSize.width)/2;
|
||||
adView.frame = newFrame;
|
||||
[UIView commitAnimations];
|
||||
}
|
||||
|
||||
- (void)dealloc {
|
||||
self.adView.delegate = nil;
|
||||
self.adView = nil;
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
|
||||
#pragma mark Table view methods
|
||||
|
||||
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
|
||||
return 10;
|
||||
}
|
||||
|
||||
|
||||
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
|
||||
|
||||
static NSString *CellIdentifier = @"Cell";
|
||||
static NSString *AdCellIdentifier = @"AdCell";
|
||||
|
||||
NSString *cellId = CellIdentifier;
|
||||
if (indexPath.row == 0) {
|
||||
cellId = AdCellIdentifier;
|
||||
}
|
||||
|
||||
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
|
||||
if (cell == nil) {
|
||||
if ([UITableViewCell instancesRespondToSelector:@selector(initWithStyle:reuseIdentifier:)]) {
|
||||
// iPhone SDK 3.0
|
||||
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId] autorelease];
|
||||
}
|
||||
else {
|
||||
// iPhone SDK 2.2.1
|
||||
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:cellId] autorelease];
|
||||
}
|
||||
if (cellId == AdCellIdentifier) {
|
||||
[cell.contentView addSubview:adView];
|
||||
}
|
||||
}
|
||||
|
||||
switch (indexPath.row) {
|
||||
case 0:
|
||||
break;
|
||||
case 1:
|
||||
if ([cell respondsToSelector:@selector(textLabel)]) {
|
||||
// iPhone SDK 3.0
|
||||
cell.textLabel.text = @"Request New Ad";
|
||||
}
|
||||
else {
|
||||
// iPhone SDK 2.2.1
|
||||
cell.text = @"Request New Ad";
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
if ([cell respondsToSelector:@selector(textLabel)]) {
|
||||
// iPhone SDK 3.0
|
||||
cell.textLabel.text = @"Roll Over";
|
||||
}
|
||||
else {
|
||||
// iPhone SDK 2.2.1
|
||||
cell.text = @"Roll Over";
|
||||
}
|
||||
break;
|
||||
default:
|
||||
if ([cell respondsToSelector:@selector(textLabel)]) {
|
||||
// iPhone SDK 3.0
|
||||
cell.textLabel.text = [NSString stringWithFormat:@"Cell %d", indexPath.row];
|
||||
}
|
||||
else {
|
||||
// iPhone SDK 2.2.1
|
||||
cell.text = [NSString stringWithFormat:@"Cell %d", indexPath.row];
|
||||
}
|
||||
}
|
||||
|
||||
return cell;
|
||||
}
|
||||
|
||||
|
||||
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
|
||||
switch (indexPath.row) {
|
||||
case 1:
|
||||
self.label.text = @"Request New Ad pressed! Requesting...";
|
||||
[adView requestFreshAd];
|
||||
break;
|
||||
case 2:
|
||||
self.label.text = @"Roll Over pressed! Requesting...";
|
||||
[adView rollOver];
|
||||
break;
|
||||
}
|
||||
[tableView deselectRowAtIndexPath:indexPath animated:YES];
|
||||
}
|
||||
|
||||
|
||||
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
|
||||
if (indexPath.section == 0 && indexPath.row == 0) {
|
||||
return CGRectGetHeight(adView.bounds);
|
||||
}
|
||||
return self.table.rowHeight;
|
||||
}
|
||||
|
||||
|
||||
#pragma mark AdWhirlDelegate methods
|
||||
|
||||
- (NSString *)adWhirlApplicationKey {
|
||||
return kSampleAppKey;
|
||||
}
|
||||
|
||||
- (UIViewController *)viewControllerForPresentingModalView {
|
||||
return [((AdWhirlSDK2_SampleAppDelegate *)[[UIApplication sharedApplication] delegate]) navigationController];
|
||||
}
|
||||
|
||||
- (NSURL *)adWhirlConfigURL {
|
||||
return [NSURL URLWithString:kSampleConfigURL];
|
||||
}
|
||||
|
||||
- (NSURL *)adWhirlImpMetricURL {
|
||||
return [NSURL URLWithString:kSampleImpMetricURL];
|
||||
}
|
||||
|
||||
- (NSURL *)adWhirlClickMetricURL {
|
||||
return [NSURL URLWithString:kSampleClickMetricURL];
|
||||
}
|
||||
|
||||
- (NSURL *)adWhirlCustomAdURL {
|
||||
return [NSURL URLWithString:kSampleCustomAdURL];
|
||||
}
|
||||
|
||||
- (void)adWhirlDidReceiveAd:(AdWhirlView *)adWhirlView {
|
||||
self.label.text = [NSString stringWithFormat:
|
||||
@"Got ad from %@, size %@",
|
||||
[adWhirlView mostRecentNetworkName],
|
||||
NSStringFromCGSize([adWhirlView actualAdSize])];
|
||||
[self adjustAdSize];
|
||||
}
|
||||
|
||||
- (void)adWhirlDidFailToReceiveAd:(AdWhirlView *)adWhirlView usingBackup:(BOOL)yesOrNo {
|
||||
self.label.text = [NSString stringWithFormat:
|
||||
@"Failed to receive ad from %@, %@. Error: %@",
|
||||
[adWhirlView mostRecentNetworkName],
|
||||
yesOrNo? @"will use backup" : @"will NOT use backup",
|
||||
adWhirlView.lastError == nil? @"no error" : [adWhirlView.lastError localizedDescription]];
|
||||
}
|
||||
|
||||
- (void)adWhirlReceivedRequestForDeveloperToFufill:(AdWhirlView *)adWhirlView {
|
||||
UILabel *replacement = [[UILabel alloc] initWithFrame:kAdWhirlViewDefaultFrame];
|
||||
replacement.backgroundColor = [UIColor redColor];
|
||||
replacement.textColor = [UIColor whiteColor];
|
||||
replacement.textAlignment = UITextAlignmentCenter;
|
||||
replacement.text = @"Generic Notification";
|
||||
[adWhirlView replaceBannerViewWith:replacement];
|
||||
[replacement release];
|
||||
[self adjustAdSize];
|
||||
self.label.text = @"Generic Notification";
|
||||
}
|
||||
|
||||
- (void)adWhirlDidAnimateToNewAdIn:(AdWhirlView *)adWhirlView {
|
||||
[self.table reloadData];
|
||||
}
|
||||
|
||||
- (void)adWhirlReceivedNotificationAdsAreOff:(AdWhirlView *)adWhirlView {
|
||||
self.label.text = @"Ads are off";
|
||||
}
|
||||
|
||||
- (void)adWhirlWillPresentFullScreenModal {
|
||||
NSLog(@"TableView: will present full screen modal");
|
||||
}
|
||||
|
||||
- (void)adWhirlDidDismissFullScreenModal {
|
||||
NSLog(@"TableView: did dismiss full screen modal");
|
||||
}
|
||||
|
||||
- (void)adWhirlDidReceiveConfig:(AdWhirlView *)adWhirlView {
|
||||
self.label.text = @"Received config. Requesting ad...";
|
||||
}
|
||||
|
||||
- (BOOL)adWhirlTestMode {
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (NSUInteger)jumptapTransitionType {
|
||||
return 3;
|
||||
}
|
||||
|
||||
- (NSUInteger)quattroWirelessAdType {
|
||||
return 2;
|
||||
}
|
||||
|
||||
- (NSString *)googleAdSenseCompanyName {
|
||||
return @"Your Company";
|
||||
}
|
||||
|
||||
- (NSString *)googleAdSenseAppName {
|
||||
return @"AdWhirl Sample";
|
||||
}
|
||||
|
||||
- (NSString *)googleAdSenseApplicationAppleID {
|
||||
return @"0";
|
||||
}
|
||||
|
||||
- (NSString *)googleAdSenseKeywords {
|
||||
return @"apple,iphone,ipad,adwhirl";
|
||||
}
|
||||
|
||||
//extern NSString* const kGADAdSenseImageAdType;
|
||||
//- (NSString *)googleAdSenseAdType {
|
||||
// return kGADAdSenseImageAdType;
|
||||
//}
|
||||
|
||||
#pragma mark event methods
|
||||
|
||||
- (void)performEvent {
|
||||
self.label.text = @"Event performed";
|
||||
}
|
||||
|
||||
- (void)performEvent2:(AdWhirlView *)adWhirlView {
|
||||
UILabel *replacement = [[UILabel alloc] initWithFrame:kAdWhirlViewDefaultFrame];
|
||||
replacement.backgroundColor = [UIColor blackColor];
|
||||
replacement.textColor = [UIColor whiteColor];
|
||||
replacement.textAlignment = UITextAlignmentCenter;
|
||||
replacement.text = [NSString stringWithFormat:@"Event performed, view %x", adWhirlView];
|
||||
[adWhirlView replaceBannerViewWith:replacement];
|
||||
[replacement release];
|
||||
[self adjustAdSize];
|
||||
self.label.text = [NSString stringWithFormat:@"Event performed, view %x", adWhirlView];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
Reference in New Issue
Block a user