iAd Banner not working - iphone

SO I used a tutorial to create an iAd Banner at the bottom of the screen and animate it into and out of the window, however the app is a tab based, and i do not quite know the correct offset, so you could tell me I would appreciate it, however the primary problem, is that the adBanner does not always appear, and when it does sometimes it is just a white box. Here is my code.
In my .h
#interface section3 <ADBannerViewDelegate>{
ADBannerView *adView;
BOOL bannerIsVisible;
}
#property (nonatomic, assign) BOOL bannerIsVisible;
//in the .m in the view did load
adView = [[ADBannerView alloc] initWithFrame:CGRectZero];
adView.frame = CGRectOffset(adView.frame, 0.0, 410.0f);
adView.requiredContentSizeIdentifiers = [NSSet setWithObject:ADBannerContentSizeIdentifierPortrait];
adView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierPortrait;
[self.view addSubview:adView];
adView.delegate = self;
self.bannerIsVisible = NO;
-(void)bannerViewDidLoadAd:(ADBannerView *)banner{
if (!self.bannerIsVisible) {
[UIView beginAnimations:#"animateAdBannerOn" context:NULL];
banner.frame = CGRectOffset(banner.frame, 0.0, -50.0f);
[UIView commitAnimations];
self.bannerIsVisible = YES;
}
}
-(void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error{
if (self.bannerIsVisible) {
[UIView beginAnimations:#"animateAdBannerOff" context:NULL];
banner.frame = CGRectOffset(banner.frame, 0.0, 50.0f);
[UIView commitAnimations];
self.bannerIsVisible = NO;
}
}
I am using Xcode 4.2.1
Thank you very much, any help would be appreciated :)

The tabbar is 44px high so u must add to one of the "50" 44 and make 410 to the full screen size of 3.5 inch means to 480 default. That should be the solution.

Related

iAd - not working properly

I'm adding iAd on my app.... I managed to have the banner sliding from the bottom (just above my tab bar, 0, 410 i guess)... but only when i launch the app the first time. when then i try to switch the wifi off on my testing device to check if i get the blank banner i get the following message:ADBannerView: WARNING A banner view (0x1b11d0) has an ad but may be obscured. This message is only printed once per banner view. Can please somebody help me??
-(void)bannerViewDidLoadAd:(ADBannerView *)banner{
if (!self.bannerIsVisible) {
[UIView beginAnimations:#"animatedAdBannerOn" context:NULL];
NSLog(#"there are ads to show");
banner.frame = CGRectOffset(banner.frame, 0, -50);
[UIView commitAnimations];
self.bannerIsVisible = YES;
}
}
//----hide banner if can't load ad.
-(void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error{
if (!self.bannerIsVisible) {
[UIView beginAnimations:#"animatedAdBannerOff" context:NULL];
NSLog(#"sorry, no ads ");
banner.frame = CGRectOffset(banner.frame, 0, 410);
[UIView commitAnimations];
self.bannerIsVisible = NO;
}
}
- (void)viewDidLoad {
[super viewDidLoad];
aBanner = [[ADBannerView alloc]initWithFrame:CGRectZero];
aBanner.frame = CGRectOffset(aBanner.frame, 0, 410);
aBanner.requiredContentSizeIdentifiers = [NSSet setWithObject:ADBannerContentSizeIdentifierPortrait];
aBanner.currentContentSizeIdentifier = ADBannerContentSizeIdentifierPortrait;
[self.view addSubview:aBanner];
aBanner.delegate=self;
self.bannerIsVisible=NO;
[super viewDidLoad];
I know something is wrong in the CGRectOffset but I'm not able to figure it out.
thanks
FIND THE PROBLEM.... WAS JUST A SIMPLE "!" HERE THE CODE FIXED:
-(void)bannerViewDidLoadAd:(ADBannerView *)banner{
if (!self.bannerIsVisible) {
[UIView beginAnimations:#"animatedAdBannerOn" context:NULL];
NSLog(#"there are ads to show");
banner.frame = CGRectOffset(banner.frame,0, -banner.frame.size.height);
[UIView commitAnimations];
self.bannerIsVisible = YES;
}
}
//----hide banner if can't load ad.
-(void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error{
if (self.bannerIsVisible) { //THE PROBLEM WAS HERE!!!!
[UIView beginAnimations:#"animatedAdBannerOff" context:NULL];
NSLog(#"sorry, no ads ");
banner.frame = CGRectOffset(banner.frame, 0, banner.frame.size.height);
[UIView commitAnimations];
self.bannerIsVisible = NO;
}
}
- (void)viewDidLoad {
[super viewDidLoad];
aBanner = [[ADBannerView alloc]initWithFrame:CGRectZero];
aBanner.frame = CGRectOffset(aBanner.frame, 0, 410);
aBanner.requiredContentSizeIdentifiers = [NSSet setWithObject:ADBannerContentSizeIdentifierPortrait];
aBanner.currentContentSizeIdentifier = ADBannerContentSizeIdentifierPortrait;
[self.view addSubview:aBanner];
aBanner.delegate=self;
self.bannerIsVisible=NO;
[super viewDidLoad];

Objective-c Hidden View animation

Hello I have a hidden view inside of my view that appears by the click of a button. But when you click on the button I want the view to do an slide up animation so it won't just appear but slide up to it's position.
Here is the code for my hidden view:
in .h:
#interface hidden_viewsViewController : UIViewController {
IBOutlet UIView *loginview;
}
#property (nonatomic, retain) IBOutlet UIView *loginview;
- (IBAction)login;
- (IBAction)logout;
And in .m
#synthesize loginview;
- (IBAction)login {
loginview.hidden = NO;
}
- (IBAction)logout {
loginview.hidden = YES;
}
- (void)viewDidLoad {
[super viewDidLoad];
loginview.hidden = YES;
}
Try, assuming the view is in portrait orientation:
- (IBAction)login {
[self.view bringSubviewToFront:loginView];
loginview.frame = CGRectMake(0, 480, 320, 480);
loginview.hidden = NO;
[UIView animateWithDuration:1.0
animations:^{
loginview.frame = CGRectMake(0, 0, 320, 480);
}];
}
you should change the frame property of your view, and you should do it within an animations block, as follows:
-(IBAction)login
{
[UIView beginAnimations:#"showView" context:nil];
[UIView setAnimationDuration:0.5];
CGRect viewNewFrame = self.view.frame;
viewNewFrame.origin.y = 0;
self.view.frame = viewNewFrame;
[UIView commitAnimations];
}
Hope it helps!

how to add a custom subview inside TTThumbviewController (Three20)

i am developing an iphone application which have to show images from server as thumbnail list. I have created thumbnailview using Three20 package TTThumbViewcontroller class.
Now i have to add banner view above the thumbnail view as shows in the image. Also i have to add the bottom banner view in the TTPhotoviewcontroller also.
can anyone guide me, how to add my custom banner view (UIView) along with either TTThumbviewConntroller or TTPhotoViewController to my parent view?
Edit:I had successfully added a subview for the controller which extends TTThumbViewcontroller. Now i have to add a subview above the TTPhotoViewController toolbar (as in the attached image).
thanks in advance.
Ram
The banner view is nothing different than a normal view. So you could do the same with any other view. Following is the code I use in my app (I have the same banner view at the bottom of the screen, you can adjust its position to put in above the tab bar):
- (void)viewDidLoad{
[super viewDidLoad];
//we don't want user to see the ads at the very first load.
//once, it succeeds, it will be animated up by the bannerViewDidLoadAd
adView = [[ADBannerView alloc] initWithFrame:CGRectMake(0, 480, 320, 50)];
adView.currentContentSizeIdentifier = ADBannerContentSizeIdentifier320x50;
[adView setDelegate:self];
[self.view addSubview:adView];
self.bannerIsVisible = NO;
}
- (void)bannerViewDidLoadAd:(ADBannerView *)banner
{
if (!self.bannerIsVisible)
{
[UIView beginAnimations:#"animateAdBannerOn" context:NULL];
adView.frame = CGRectMake(0, 346, 320, 50);
[UIView commitAnimations];
self.bannerIsVisible = YES;
}
}
- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error
{
if (self.bannerIsVisible)
{
[UIView beginAnimations:#"animateAdBannerOff" context:NULL];
adView.frame = CGRectMake(0, 480, 320, 50);
[UIView commitAnimations];
self.bannerIsVisible = NO;
}
}
- (void)dealloc{
adView.delegate = nil;
[adView release];
[super dealloc];
}

iAd in iPhone animates when not loaded

I have added a banner view for implementing iAd in the bottom of the screen. But when running on the simulator the banner view is slightly above the frame fixed for it. It appears as a transparent strip and is not selectable. After sometime it automatically comes to the bottom as a black strip saying Test Advertisement.
I want the banner View to stick to the bottom and not animate.
Here is my code. The adView declaration code:
adView = [[[ADBannerView alloc] initWithFrame:CGRectOffset(CGRectZero, 0, 350)] autorelease];
adView.frame = CGRectMake(0,340,320,25);
adView.requiredContentSizeIdentifiers = [NSSet setWithObject:ADBannerContentSizeIdentifier320x50];
adView.currentContentSizeIdentifier = ADBannerContentSizeIdentifier320x50;
adView.autoresizingMask = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleRightMargin;
adView.tag = 111;
[self.navigationController.view addSubview:adView];
adView.delegate = self;
self.bannerIsVisible = NO;
adView.hidden = YES;
Here are the delegate methods.
- (void)bannerViewDidLoadAd:(ADBannerView *)banner
{
if (!self.bannerIsVisible) {
[UIView beginAnimations:#"animateAdBannerOff" context:NULL];
// banner is invisible now and moved out of the screen on 50 px
banner.frame = CGRectOffset(banner.frame, 0, 50);
[UIView commitAnimations];
self.bannerIsVisible = YES;
}
}
// When iAd is not availale on the banner
- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error
{
if (self.bannerIsVisible) {
[UIView beginAnimations:#"animateAdBannerOff" context:NULL];
// banner is visible and we move it out of the screen, due to connection issue
banner.frame = CGRectOffset(banner.frame, 0, 520);
[UIView commitAnimations];
self.bannerIsVisible = NO;
}
}
I am not able to understand the problem. Kindly help.
First.
When the main view is loaded how are the objects placed in it initially? I always place them in right positions inside viewDidLoad method. So place your banner below the bottom of the main view making sure that
myBannerFrame.origin.x = 0;
myBannerFrame.origin.y = mainView.frame.size.height;
[myBanner setFrame:myBannerFrame]; // no need for animation here!
Also viewDidLoad is a good place to set your flag self.bannerIsVisible to FALSE.
Second. Do not use fixed pixel values like here
banner.frame = CGRectOffset(banner.frame, 0, 50);
instead of 50 you better put banner.frame.size.height
This will help you to avoid many errors and misalignments.

Fade from iPhone default bitmap into main app

What's the easiest/fastest/most efficient way to perform a gradual (0.5 sec) fade from Default.png to the initial app view?
My initial try, which doesn't work so well .. it's Saturday night, let's see if we can do better :)
UIImageView* whiteoutView = [[UIImageView alloc] initWithFrame:self.view.frame]; // dealloc this later ??
whiteoutView.image = [UIImage imageNamed:#"Default.png"];
whiteoutView.alpha = 1.0;
[self.view.frame addSubview:whiteoutView];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDelay:0.5];
whiteoutView.alpha = 0;
[UIView commitAnimations];
What about:
UIImageView* whiteoutView = [[[UIImageView alloc] initWithFrame:self.view.frame] autorelease];
if (whiteoutView != nil)
{
whiteoutView.image = [UIImage imageNamed:#"Default.png"];
[self.view addSubview:whiteoutView];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration: 0.5];
whiteoutView.alpha = 0.0;
[UIView commitAnimations];
}
(The things you had wrong were setAnimationDelay vs setAnimationDuration, not properly releasing the view and trying to add the view to self.view.frame instead of self.view. The compiler should have caught that last one. Did it?)
Here's a simple view controller that fades out the default image and removes itself from the view hierarchy. The advantage to this approach is that you can use this without modifying your existing view controllers...
#interface LaunchImageTransitionController : UIViewController {}
#end
#implementation LaunchImageTransitionController
- (void)viewDidLoad {
[super viewDidLoad];
self.view = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Default.png"]] autorelease];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:.5];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:#selector(imageDidFadeOut:finished:context:)];
self.view.alpha = 0.0;
[UIView commitAnimations];
}
- (void)imageDidFadeOut:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context
{
[self.view removeFromSuperview];
//NOTE: This controller will automatically be released sometime after its view is removed from it' superview...
}
#end
Here is how you might use it in your app delegate:
- (void)applicationDidFinishLaunching:(UIApplication *)application {
//create your root view controller, etc...
UIViewController *rootController = ....
LaunchImageTransitionController *launchImgController = [[[LaunchImageTransitionController alloc] init] autorelease];
[window addSubview:rootController.view];
[window addSubview:launchImgController.view];
[window makeKeyAndVisible];
}
Other than using setAnimationDelay: instead of setAnimationDuration:, it looks pretty good. What don't you like about the results?
Edit: Wow beaten hard.