Game Development Community

How to implement iAd

by SysRat · in iTorque 2D · 10/27/2011 (3:52 am) · 11 replies

There is my simple way to implement iAd in to your game:

1. Add "iAd.framework" to your project.

2. Add UIViewController subclass to your project with XIB file. Name it "myAd".

3. Open "myAd.xib" file and drag "AD BannerView" object to the screen. Set it hidden. Change orientation to Landscape both for "View" and "AD BannerView" if needed. Connect the "ADBannerView" to the our View Controller delegate.

4. Open "myAd.h" file and add "#import "iAd/ADBannerView.h" to the very top, then, add "<ADBannerViewDelegate>":
#import <UIKit/UIKit.h>
#import "iAd/ADBannerView.h"

@interface myAd : UIViewController <ADBannerViewDelegate>
{
}

@end

5. Open "myAd.m" file

for landscape mode add:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);    
}

- (void)bannerViewActionDidFinish:(ADBannerView *)banner
{
    self.view.frame = CGRectMake(288, 0, 32, 480);
}
for portrait mode add:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);    
}

- (void)bannerViewActionDidFinish:(ADBannerView *)banner
{
    self.view.frame = CGRectMake(0, 0, 320, 50);
}
and for both add:
-(void)bannerViewDidLoadAd:(ADBannerView *)banner
{
    banner.hidden = NO;
}
6. Open "TGBApplDelegate.mm" file. To the very top add:
#import "myAd.h"
Then, find "applicationDidFinishLaunching" function and add to the end:

for landscape mode:
UIViewController *view_controller = [[myAd alloc] init];
[window addSubview: view_controller.view];
view_controller.view.frame = CGRectMake(288, 0, 32, 480);
for portrait mode:
UIViewController *view_controller = [[myAd alloc] init];
[window addSubview: view_controller.view];
view_controller.view.frame = CGRectMake(0, 0, 320, 50);
or you can call this view from torque script in your game (see iTorque2D documents).

7. Change background opacity of "View" to 0% to hide it from the screen.

Maybe it's not the best way to implement iAd, but it works fine for me ;)

#1
08/27/2012 (11:41 pm)
Hi SysRat,

I believe your solution is great and I really want to implement the iAd in my app by your way. I've got 2 problems when I was trying.

1. How to "Connect the "ADBannerView" to the our View Controller delegate"?
2. Change background opacity of "View" to 0% to hide it from the screen. How to do this?

Could you tell me more on them? Or anyone else can help?

Thanks a lot!
#2
12/31/2012 (4:38 pm)
Seems to display correctly but when you close the ad your view is still there and obstructs your "layer" which you interact with your app. A good test to prove this is that you don't set your opacity of your view to 0%. Seems to need a way to remove the view to hidden so you can interact with your app again
#3
12/31/2012 (5:15 pm)
We found iAd to be very poor performer for revenue and Chartboost is about 1000 times better.
#4
12/31/2012 (5:24 pm)
@Scott Wilson do you have a resource? Looking to go some sort of ad route for my iTorque 2D app and I keep hitting walls.
#5
12/31/2012 (6:47 pm)
@Michael, you need to sign up and download the SDK.

https://www.chartboost.com

They have examples, it is all very straightforward, let me know if you get stuck.
#6
12/31/2012 (8:23 pm)
Thanks @Scott Wilson. Other than missing adding a library on the first attempt I got it working. Thanks for the tip. Extremely easy.
#7
01/01/2013 (3:24 am)
@Michael, sit back and enjoy the revenue :)
#8
01/03/2013 (10:57 am)
@Scott Wilson do you know if it is against the terms of use to create a console function that will call the ad up for additional times other than startup? I implemented it and call it when a player checks their high scores. Will probably randomize it though so not to come up everytime and be annoying.
#9
01/03/2013 (4:32 pm)
@Michael Cozzolino - you can definitely show as many ads as you'd like. I recommend emailing support@chartboost.com if you have any questions. I've emailed them in the past and they've been very helpful with all my questions. Also, I found help.chartboost.com/faq pretty useful as well.
#10
01/04/2013 (1:52 am)
@Michael, I'r recommend defining as many placements as you can; start game, end game, end level, pause game, buy item, more games etc

Check for an ad in every single placement.

You can always switch off placements in the 'campaign logic' section of your campaign. To turn ads off completely for an app then just pause the campaign.
#11
01/04/2013 (2:38 pm)
Thanks for the info Scott. To anyone else I hope to write up a tutorial this weekend. It's dead simple and think a lot for Torque devs could benefit from an ad revenue stream. I'll post a link here.

Edit

Here is a link to the resource I created to add ChartBoost to your App.
www.garagegames.com/community/blogs/view/22096