iAd Banner - Technical only

Previous topic - Next topic

matchy

No. Why don't you try it?

ampos

Sorry Matchy, but he can not try because it does not work.

matchy

Oh. The only current issue I have is that the banner needs to tell glb that it's being pressed and I'm not sure how to do that from the iAd delegate (or any other running objc in the background).

Just to note, xcode 4.3 beta now has full-screen iAds also.

Leginus

Sorry, I have deleted off topic post

matchy


This had just been accepted with GLB and iAd!!! It's free so please download it and tell me if the adverts are display okay!

http://www.glbasic.com/forum/index.php?topic=3857.msg44202#msg44202

Moebius

Nice job matchy, but unfortunately just after the loading animation seems to complete the app crashes  :doubt:
I'm using an iPod Touch 2G in Australia.
Endless Loop: n., see Loop, Endless.
Loop, Endless: n., see Endless Loop.
- Random Shack Data Processing Dictionary

Ian Price

It loads and appears to work fine at first - I got the main "game" and an ad for LYNX deo at the top, stating "Tap Here" which when tapped took me to the LYNX EXCITE  site. X'ing brought me back to the app. All good so far.

However, when I went back to app (now with a different ad at the top) there was no sound and the "buttons" went into spasm - the wavy lines kept playing in each "button" I'd pressed before going to the ad site. Pressing a new button caused more wavy lines, but no sound. Exiting the app with HOME and restarting made no difference - the app stayed the same. Turning off and back on again was the same.

I tried shaking it and eventually the buttons cleared, but then only the top three buttons went wavy, but still with no sound. The buttons responded to my touch (the colour changed and the highlight moved), but they didn't produce any waves (or sound).

I've turned off, shaken, exited and pressed everthting multiple times, but still no joy. Oh and the ads aren't appearing now either.

So it's a partial success... At least it didn't crash.

BTW iPod Touch 2G (Sept 2010) 32GB.
I came. I saw. I played.

matchy

#67
Oh...thanks so much for testing, dudes. At least the adverts are showing because they don't show for me for some reason, even on non-GLB apps...only test ads. There's no (required) code to detect that the advert was selected.

Anyhow, I'll have to review my code regarding missing sound and lines, but I think this is not a iAd issue as I experience missing "waves" on WinCE also so I removed them.
Just to note, the sound app creates wav files user folder, loads them into memory, then deletes them.

DVD Guy

Hi Matchy -

My finger is tired :D
I tested on an iphone 4 (8 GB) w/ ios 4.1. No problems, no crashes - everything seems to work fine.  I haven't see an iad yet, though - I'm in the U.S. (not sure if that has any relevance).  I've read that iads are in short supply due to a significant downturn in sales after Christmas, so it may take a while to see them. I'll let you know if I do. 

matchy

The only time I don't receive test adverts with an error that they are not available, is when the device date and time are incorrect. Sometimes it can be confusing but it's safe to know that they are displaying.

matchy

#70
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:
Code (glbasic) Select

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:
Code (glbasic) Select

// 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:
Code (glbasic) Select

// 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.

ampos

Can someone explain to a full-idiot how to use this?

BTW, your app shows me "test ads"

matchy

Add the class to the xcode resources, iAd framework and call this from GLB:
Code (glbasic) Select

IMPORT "C" void glb_BannerInit()


When an app goes live on the App Store, it should be showing real ads. It is strange that you are getting tests ads (I presume it says "Test Advertisement") which are only available before the app is approved.

Ampos, please note: I don't appreciate your attitude be degrading yourself and there's no need for sly remarks.

ampos

#73
When I said "full-idiot" I was meaning a guide to total noobs, as really this c things overpasses me, and also I am not english speaker and we can get some lñanguage barriers too (or at least, the way we voiced our ideas).

Continuing with the post theme, let me clarify if I get this...

In my glb program I should insert at the end this:

Code (glbasic) Select
INLINE
...your c code
ENDINLINE


and in the xcode proyect, in resources, add "iad framework"...

Then just at anypoint of the program

Code (glbasic) Select

?IFDEF IPHONE
glb_BannerInit()
?ENDIF


ALso I remember there was glb_show() and glb_hide() and perhaps others. Are they still there, or aren't they needed anymore?


About the test app, maybe I am wrong as I can not find again the doc were how iad works was explained in apple website, but I remember there was an explanation that you should change something once the app was released...

matchy

Code (glbasic) Select

ad_animate()

FUNCTION ad_animate:
glb_BannerInit()
WHILE TRUE
PRINT "AdBanner Test", 10, 100
SHOWSCREEN
WEND
ENDFUNCTION

?IFDEF IPHONE
IMPORT "C" void glb_BannerInit()
?ELSE
FUNCTION glb_BannerInit:
DEBUG "[WIN] Banner Init (sim) \n"
ENDFUNCTION
?ENDIF