First, you need to open the main.h
header file and make some changes to it. We dive here into Object-C/C++ code, so be confused if the code looks different from the native Monkey code:
import
statement for the MobFox/MobFox.h
file:#include <OpenAL/alc.h> #import <MobFox/MobFox.h> // ***** MonkeyView ***** @interface MonkeyView : UIView{
MobFoxBannerViewDelegate
to the Monkey view controller:// ***** MonkeyViewController ***** @interface MonkeyViewController : UIViewController <MobFoxBannerViewDelegate> { @public } @end
main.m
file, the heart of your Monkey code. Insert the viewDidLoad
method into the MonkeyViewController
implementation and call its super
implementation. Place the method right under the shouldAutorotateToInterfaceOrientation
method, which controls how the app will be able to rotate natively:@implementation MonkeyViewController -(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{ //.......... } - (void)viewDidLoad { [super viewDidLoad];
MobFoxBannerView *bannerView = [[MobFoxBannerView alloc] initWithFrame:
The frame for creating the banner will be at the bottom of the screen. So, at the beginning, the ad is hidden in the off-screen area. You can't use the view sizes, as the view in Monkey is very small by default:
CGRectMake(0, [[UIScreen mainScreen] bounds].size.height, 320, 50)];
bannerView.delegate = self;
bannerView.backgroundColor = [UIColor darkGrayColor];
refreshAnimation
for the banner view to the CurlDown
animation type:bannerView.refreshAnimation = UIViewAnimationTransitionCurlDown;
[self.view addSubview:bannerView]; }
This method creates a new banner view, but you still need to let MobFox know your MobFox publisher ID. This is done inside the publisherIdForMobFoxBannerView
method:
#pragma mark MobFox Delegate
publisherIdForMobFoxBannerView
method, with NSString
as a return value and banner
as a parameter:- (NSString *)publisherIdForMobFoxBannerView:(MobFoxBannerView *)banner {
return @"InsertYourIdHere"; }
The banner was created in the off-screen area. When it receives an ad from MobFox, it should slide into the visible area. This is done with the next method.
mobfoxBannerViewDidLoadMobFoxAd
method. The parameter is banner:
- (void)mobfoxBannerViewDidLoadMobFoxAd:(MobFoxBannerView *)banner {
NSLog(@"MobFox: did load ad");
[UIView beginAnimations:@"MobFox" context:nil]; [UIView setAnimationDuration:1];
50
pixels, so we place it accordingly:banner.frame = CGRectMake(0, self.view.bounds.size.height - 50, 320, 50);
//banner.frame = CGRectMake(0, 0, 320, 50); [UIView commitAnimations]; }
Once an ad is received, the banner view will slide into the visible screen area. But sometimes, ads are not available. It could be that MobFox doesn't serve an ad, or the device has no connection to the Internet. For this, we need a method to slide the banner view outside the screen area.
didFailToReceiveAdWithError
with error
as a parameter.- (void)mobfoxBannerView:(MobFoxBannerView *)banner didFailToReceiveAdWithError:(NSError *)error {
NSLog(@"MobFox: did fail to load ad: %@", [error localizedDescription]);
[UIView beginAnimations:@"MobFox" context:nil]; [UIView setAnimationDuration:1];
banner.frame = CGRectMake(0, self.view.bounds.size.height, 320, 50); [UIView commitAnimations];
} @end
You have added all the needed methods to your XCODE project to display MobFox ads inside your game. If you now build and run the project inside the simulator, you should see a test banner ad:
After you have finished the implementation, two more steps have to be taken to display real ads in your game. First, change the URL link to your app inside the app store once you know it.
Second, when the application is going live, request the activation of ads from MobFox. This can be done from your MobFox account, inside the list of apps.