Here's the source which works for iPhone and iPad. This version is set for top portrait with orientation omitted.
There are two files "AppViewController.h" and "AppViewController.mm" that need to be created in a new folder "Classes".
Steps 1 - 21
1. Log on to windows and open GLB and create an new project called "AdBannerTest".
2. Paste the following GLB code:
glb_BannerInit()
WHILE TRUE
DRAWRECT 0,0,320,480
SHOWSCREEN
WEND
?IFDEF IPHONE
IMPORT "C" void glb_BannerInit()
?ELSE
FUNCTION glb_BannerInit:
DEBUG "[WIN] Banner Init (sim) \n"
ENDFUNCTION
?ENDIF
3. Save the project
4. Run the AdBannerTest program.
4. Build for iPhone.
5. Close GLB.
6. Open the "AdBannerTest\Xcode\" folder with Windows Explorer.
7. Two files for Xcode need preparing. Create a folder named "Classes"
8. Create two new text files and rename them to "AppViewController.h" and "AppViewController.mm"
9. Open the blank file "AppViewController.h" and paste the following ObjC code:
// This filename is "AppViewController.h"
#import "iAd/ADBannerView.h"
@interface AppViewController : UIViewController <ADBannerViewDelegate> {
ADBannerView * bannerView;
UIView * _appView;
UIWindow * _appWindow;
}
@property (nonatomic, retain) IBOutlet UIView * appView;
@property (nonatomic, retain) IBOutlet ADBannerView * bannerView;
@property (nonatomic, retain) IBOutlet UIWindow * appWindow;
- (void)createBannerView;
- (void)showBanner;
- (void)hideBanner;
- (void)changeBannerOrientation:(UIInterfaceOrientation)toOrientation;
@end
10. Save the file "AppViewController.h" and close it.
11. Open the file "AppViewController.mm" and paste the following code:
// This filename is "AppViewController.mm"
#import "AppViewController.h"
@implementation AppViewController
@synthesize appView = _appView;
@synthesize bannerView; // = _bannerView;
@synthesize appWindow = _appWindow;
# pragma mark -
# pragma mark View
- (void)viewDidLoad {
[super viewDidLoad];
// NSLog(@"viewDidLoad");
}
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
// NSLog(@"viewDidAppear");
}
//- (void)viewWillAppear:(BOOL)animated {
// NSLog(@"viewWillAppear");
// if (bannerView) {
// UIInterfaceOrientation orientation=self.interfaceOrientation;
// [self changeBannerOrientation:orientation];
// }
//}
- (void)dealloc {
[super dealloc];
}
//- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
//
// return (interfaceOrientation == UIInterfaceOrientationPortrait) | (interfaceOrientation == UIInterfaceOrientationLandscapeLeft) | (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
//}
#pragma mark -
#pragma mark ADBanner
//- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
//if (bannerView) {
// [self changeBannerOrientation:toInterfaceOrientation];
//}
// NSLog(@"shouldAutorotate");
//}
- (void)changeBannerOrientation:(UIInterfaceOrientation)toOrientation {
if (UIInterfaceOrientationIsLandscape(toOrientation)) {
bannerView.currentContentSizeIdentifier=ADBannerContentSizeIdentifierLandscape;
self.view.frame=CGRectMake(0,0, 320, 120);
} else {
bannerView.currentContentSizeIdentifier=ADBannerContentSizeIdentifierPortrait;
self.view.frame=CGRectMake(0,0, 480, 100);
}
}
- (void)bannerViewDidLoadAd:(ADBannerView *)banner {
NSLog(@"bannerViewDidLoad");
// self.bannerView.hidden=NO;
[self showBanner];
}
- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error {
// self.bannerView.hidden=YES;
// NSLog(@"bannerView");
NSLog(@"E R R O R: '%@'",error);
// [self hideBanner];
}
- (void)createBannerView {
// NSLog(@"Banner creating...");
_appWindow = [[UIApplication sharedApplication] keyWindow];
bannerView=[[[ADBannerView alloc] init] autorelease];
bannerView.delegate=self;
self.view.frame = CGRectMake(0,0, 768, 66);
bannerView.frame=CGRectMake(0,-66, 768, 66);
bannerView.currentContentSizeIdentifier=ADBannerContentSizeIdentifierPortrait;
[self.view addSubview:self.bannerView];
[_appWindow addSubview:self.view];
[_appWindow makeKeyWindow];
// [_appWindow makeKeyAndVisible];
}
- (void)showBanner {
// NSLog(@"Show banner");
CGRect bannerFrame=bannerView.frame;
bannerFrame.origin.y=0;
[UIView beginAnimations:@"showBanner" context:NULL];
bannerView.frame=bannerFrame;
[UIView commitAnimations];
}
- (void)hideBanner {
// NSLog(@"Hide banner");
CGRect bannerFrame=bannerView.frame;
bannerFrame.origin.y=-bannerFrame.size.height;
bannerView.frame=bannerFrame;
}
#pragma mark -
#pragma mark GLB
- (void)initBanner {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc]init];
[self performSelectorOnMainThread:@selector(createBannerView) withObject:nil waitUntilDone:YES];
[pool release];
}
@end
extern "C" void glb_BannerInit() {
AppViewController * UIGlbasic;
UIGlbasic = [[AppViewController alloc] init];
[UIGlbasic createBannerView];
// [UIGlbasic release];
[UIGlbasic retain];
}
13. Save the "AppViewController.mm" file and close it.
14. If there is no Mac on the LAN, copy the "AdBannerTest\XCode\" folder to a USB drive.
14. Log out of Windows.
15. Log in to Mac.
16. Open the "AdBannerTest\XCode\" folder with Mac Finder.
17. Open the Xcode project.
18. Open the "AdBannerTest\XCode\Classes" folder with Mac Finder.
19. Drag the files "AppViewController.h" and "AppViewController.mm" to the Class folder in Xcode.
20. Add the iAd Framework.
21. Compile for iPhone.