Adwhirl + Cocos2d iPhone iPad implementation tutorial

I read a blogpost over at: http://emeene.com/2010/10/adwhirl-cocos2d-iphone/ Couldn’t get it to work while following the tutorial. There’s also a lot of extra code that I didn’t need (such as offline ad storage, and optional ads for free and paid versions). Anyways, here’s how I implemented it:
1. Follow the readme first, add any extra frameworks as needed for each of your ad networks and add the files into your project.
2. In the AppDelegate.h here’s what mine looks like (imported AdwhirlDelegateProtocol.h, specify that this AppDelegate will follow the AdwhirlDelegate, add the property for root controller, and list out the extra methods needed to implement the AdwhirlDelegate):

#import <UIKit/UIKit.h>
#import "AdWhirlDelegateProtocol.h"
@class RootViewController;

@interface AppDelegate : NSObject <UIApplicationDelegate, AdWhirlDelegate> {
	UIWindow			*window;
	RootViewController	*viewController;
}
- (NSString *)adWhirlApplicationKey;
- (UIViewController *)viewControllerForPresentingModalView;
- (void)applicationDidFinishLaunching:(UIApplication *)application;
@property (nonatomic, retain) UIWindow *window;
@property (nonatomic, retain) RootViewController *viewController;
@end

3. In AppDelegate.m, implemented the extra methods as follows (make sure to import “AdWhirlView.h”):

- (NSString *)adWhirlApplicationKey {
	return @"XXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
}
- (UIViewController *)viewControllerForPresentingModalView {
	return viewController;
}
- (void)adWhirlDidReceiveAd:(AdWhirlView *)adWhirlView { 
	
    [adWhirlView rotateToOrientation:UIInterfaceOrientationLandscapeRight]; //My game is landscape only, adjust yours accordingly
	CGSize adSize = [adWhirlView actualAdSize];
	CGRect newFrame = adWhirlView.frame;
	
	newFrame.size = adSize;
	newFrame.origin.x = [[CCDirector sharedDirector] winSize].width/2-adSize.width/2;
	newFrame.origin.y = [[CCDirector sharedDirector] winSize].height-adSize.height;
	
	adWhirlView.frame = newFrame;
	
}

Make sure to input your adwhirlapplicationkey (get it from the adwhirl website).

4. Lastly, add this to the end of applicationDidFinishLaunching in AppDelegate.m

	AdWhirlView *adWhirlView = [AdWhirlView requestAdWhirlViewWithDelegate:self];
	[[[CCDirector sharedDirector] openGLView] addSubview:adWhirlView];

The ads should now be visible.

Comments

  1. Oliver Foggin says

    I’ve also been having a nightmare trying to get this to work (I’ve been following the emeene tutorial too) and getting errors all over the place.

    I';ll give this a whirl (geddit? :-) ) tonight and let you know how it goes. It looks liek it addresses the couple of issues I was having though.

    Thanks

  2. Oliver Foggin says

    Hi,

    I finally got it running except it isn’t showing the ads :(

    I have a feeling that I’m not actually creating the viewController anywhere.

    Where does this need to be created and what does it need to be assigned to?

    Thanks very much!

    Oliver

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

 

WP-SpamFree by Pole Position Marketing