iAd Banner white continue to showing - ios

Adding a iAd banner in my app, but when the banner is empty (white) the banner not become hidden, i try two type of code one is:
on my .h
#import <iAd/iAd.h>
#interface HomeViewController : UIViewController <ADBannerViewDelegate> {
ADBannerView *homeBanner;
}
//----------------------------------iAd BANNER-------------------------//
#property (nonatomic, assign) BOOL bannerIsVisible;
#property (nonatomic, strong) IBOutlet ADBannerView *homeBanner;
#end
on class .m
#synthesize homeBanner, bannerIsVisible;
//------------iAd Banner---------------------------------------//
- (void)bannerViewDidload:(ADBannerView *)abanner {
if (!self.bannerIsVisible){
[UIView beginAnimations:#"animationAdBannerOn" context:NULL];
homeBanner.frame = CGRectOffset(homeBanner.frame, 0.0, 50.0);
[UIView commitAnimations];
self.bannerIsVisible = YES;
}
}
- (void)bannerView:(ADBannerView *)aBanner {
if (!self.bannerIsVisible){
[UIView beginAnimations:#"animationAdBannerOff" context:NULL];
homeBanner.frame = CGRectOffset(homeBanner.frame, 0.0, -320.0);
[UIView commitAnimations];
self.bannerIsVisible = NO;
}
}
with this code if the banner is white, continue showing.
Try to a second code:
on my .h
#import <iAd/iAd.h>
#interface HomeViewController : UIViewController <ADBannerViewDelegate> {
ADBannerView *homeBanner;
}
//----------------------------------iAd BANNER-------------------------//
#property (nonatomic, strong) IBOutlet ADBannerView *homeBanner;
#end
and on .m
- (void)viewDidLoad {
[super viewDidLoad];
[homeBanner setHidden:YES];
}
- (void)bannerViewDidload:(ADBannerView *)banner {
[homeBanner setHidden:NO];
NSLog(#"Showing");
}
- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error {
[homeBanner setHidden:YES];
NSLog(#"Hidden");
}
and finally have the same problem.
Any idea?
Thanks.

Did you set the delegate for the bannerView?
Try this in you viewDidLoad -
[homeBanner setDelegate:self];

Related

iAd Banner implementation on Game Over Class

So I have a game that has a game over class. I also have an iAd banner at the bottom of the screen, but it stays there for the entire length of the game. I want the banner to appear when the game ends, and disappear when the user presses the restart game button.
In my RootViewController.mm I have the following code
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
ADBannerView *adView = [[ADBannerView alloc] initWithFrame: CGRectMake(0,self.view.frame.size.height - 50, 320, 50)];
[self.view addSubview:adView];
}
How would I go about only displaying an iAd banner when the game ends?
You should create a Shared iAd Banner in your AppDelegate and then present the ADBannerView on which ever ViewController you like. This implementation takes into account that an ADBannerView will not always receive an ad from the iAd network. The ADBannerView's alpha property is set depending on whether it receives an ad or not using the ADBannerView's delegate methods. This way, you can just display and hide the ADBannerView when the game ends and when you reset it knowing that the ADBannerView will only be visible if it has an ad to present.
AppDelegate.h
#import <UIKit/UIKit.h>
#import iAd; // Import iAd
#interface AppDelegate : UIResponder <UIApplicationDelegate, ADBannerViewDelegate> // Include delegate
#property (strong, nonatomic) UIWindow *window;
#property (strong, nonatomic) ADBannerView *adView;
AppDelegate.m
#import "AppDelegate.h"
#interface AppDelegate ()
#end
#implementation AppDelegate
-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Create our one ADBannerView
_adView = [[ADBannerView alloc]init];
// Set delegate and hide banner initially
_adView.delegate = self;
_adView.hidden = YES;
return YES;
}
// iAd delegate methods
-(void)bannerViewDidLoadAd:(ADBannerView *)banner {
NSLog(#"bannerViewDidLoadAd");
_adView.alpha = 1.0;
}
-(void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error {
NSLog(#"didFailToReceiveAdWithError: %#",error);
_adView.alpha = 0.0;
}
ViewController.m
#import "ViewController.h"
#import "AppDelegate.h"
#interface ViewController () {
AppDelegate *appDelegate;
}
#end
#implementation ViewController
-(void)viewDidLoad {
[super viewDidLoad];
// Create reference to our app delegate
appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
// Position
appDelegate.adView.center = CGPointMake(self.view.center.x,
self.view.frame.size.height - appDelegate.adView.frame.size.height / 2);
// Add to view
[self.view addSubview:appDelegate.adView];
// I'm just calling the gameOver function for example
// You should add the contents of the function to something more suitable
[self gameOver];
}
-(void)gameOver {
// Unhide the ADBannerView in which ever function is called first in the gameover view
// I'm guessing you have a UIButton that this would work in
appDelegate.adView.hidden = NO;
}
-(void)gameReset {
// When you reset the game hide the ADBannerView
// I'm guessing you have a UIButton that this would work in also
appDelegate.adView.hidden = YES;
}
You can try this bit of code:
When your game ends: [self showiAdBanner];
When your game begins: [self hideiAdBanner];
If you use this code, you'll want to replace this:
ADBannerView *adView = [[ADBannerView alloc] initWithFrame: CGRectMake(0,self.view.frame.size.height - 50, 320, 50)];
[self.view addSubview:adView];
with this:
[self showiAdBanner];
Two methods to show iad and hide iad:
- (void)showiAdBanner {
if( !_adView ) { // only add to view if it's not already there
_adView = [[ADBannerView alloc] initWithFrame:CGRectMake(0, self.view.frame.size.height - 50, 320, 50)]; //initialize it
_adView.delegate = self; // set delegate
}
_adView.hidden = NO; //reveal it
_bannerIsVisible = YES; //set bool to yes
}
- (void)hideiAdBanner {
_adView.hidden = YES; //hide it
_bannerIsVisible = NO; // set bool to no
}
Remember to add this part as well:
#interface RootViewController () <ADBannerViewDelegate>
#property (nonatomic, strong) ADBannerView *adView;
#property (nonatomic) BOOL bannerIsVisible;
#end
If you want to get fancy, instead of hiding it, you can animate/fade it out.

Shared iAd banner bannerViewDidLoadAd not being called

I am using the following code to setup a shared iAd banner.
AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
_adView = [[ADBannerView alloc]init];
}
ViewController.m
-(void) viewWillAppear:(BOOL)animated {
AppDelegate *appdelegate = (AppDelegate *)[[UIApplication sharedApplication ]delegate];
_adView = [appdelegate adView];
_adView.delegate = self;
self.canDisplayBannerAds = true;
}
- (void)bannerViewDidLoadAd:(ADBannerView *)banner {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1];
[banner setAlpha:1];
[UIView commitAnimations];
}
- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1];
[banner setAlpha:0];
[UIView commitAnimations];
}
bannerView:didFailToReceiveAdWithError is getting called as expected but bannerViewDidLoadAd is never called. I am trying to move some buttons up on the screen when the iAd banner loads.
Your shared banner does not appear to be just one ADBannerView. It looks like you've set multiple #property's for your ADBannerView in your AppDelegate.h and your ViewController.h. Also, self.canDisplayBannerAds = true is creating an entirely new and different ADBannerView for you. self.canDisplayBannerAds = true can be used for a no hassle way of implementing iAds in your application. This will create a ADBannerView for you and show or hide the ADBannerView depending on whether it receives an ad or not from the iAd network. You will want to remove this from your viewDidLoad if you plan to implement a ADBannerView yourself.
Here is what your implementation of your shared ADBannerView should look like:
AppDelegate.h
#import <UIKit/UIKit.h>
#import iAd;
#interface AppDelegate : UIResponder <UIApplicationDelegate> {
}
#property (strong, nonatomic) UIWindow *window;
#property (strong, nonatomic) ADBannerView *iAdView;
#end
AppDelegate.m
-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
_iAdView = [[ADBannerView alloc]init];
return YES;
}
ViewController.h
#import <UIKit/UIKit.h>
#import "AppDelegate.h"
#interface ViewController : UIViewController <ADBannerViewDelegate>
#end
ViewController.m
#import "ViewController.h"
#interface ViewController ()
#end
#implementation ViewController {
AppDelegate *appDelegate;
}
-(void)viewDidLoad {
[super viewDidLoad];
appDelegate = (AppDelegate *)[[UIApplication sharedApplication ]delegate];
appDelegate.iAdView.delegate = self;
appDelegate.iAdView.frame = CGRectMake(0, 0, appDelegate.iAdView.frame.size.width, appDelegate.iAdView.frame.size.height);
[self.view addSubview:appDelegate.iAdView];
// You created another adView property in your ViewController.h?
//_adView = [appdelegate adView];
//_adView.delegate = self;
// This will actually create ANOTHER ADBannerView
// Do not use when creating your own ADBannerView
//self.canDisplayBannerAds = true;
}
-(void)bannerViewDidLoadAd:(ADBannerView *)banner {
NSLog(#"iAd LOADED");
[UIView beginAnimations:nil context:NULL];
appDelegate.iAdView.alpha = 1.0;
[UIView commitAnimations];
}
-(void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error {
NSLog(#"iAd FAILED");
[UIView beginAnimations:nil context:NULL];
appDelegate.iAdView.alpha = 0.0;
[UIView commitAnimations];
}

Can someone please help me understand why my view does not shift up and how I can fix it?

I am a beginner to IOS programming (and programming in general) and I simply don't understand why my code does not shift everything on my screen when the keyboard appears on the screen, as I intend it to. Can someone please help me understand what I am missing here?
ViewController.h
#interface ViewController : UIViewController <UITextFieldDelegate> {
}
#property (strong, nonatomic) IBOutlet UITextField *firstRoommateTextField;
#property (strong, nonatomic) IBOutlet UITextField *secondRoommateTextField;
#property (strong, nonatomic) IBOutlet UILabel *calculatedValueLabel;
- (IBAction)calculateButton:(UIButton *)sender;
- (IBAction)textFieldDismiss2:(id)sender;
- (IBAction)textFieldDismiss1:(id)sender;
#end
ViewController.m
#import "ViewController.h"
#interface ViewController ()
#end
#implementation ViewController
#synthesize firstRoommateTextField = _firstRoommateTextField;
#synthesize secondRoommateTextField = _secondRoommateTextField;
- (void)viewDidLoad
{
[super viewDidLoad];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void) animateTextField: (UITextField*) textField up: (BOOL) up
{
const int movementDistance = 210; // tweak as needed
const float movementDuration = 0.3f; // tweak as needed
int movement = (up ? -movementDistance : movementDistance);
[UIView beginAnimations: #"anim" context: nil];
[UIView setAnimationBeginsFromCurrentState: YES];
[UIView setAnimationDuration: movementDuration];
self.view.frame = CGRectOffset(self.view.frame, 0, movement);
[UIView commitAnimations];
}
- (void)textFieldDidBeginEditing:(UITextField *)textField
{
[self animateTextField: textField up: YES];
}
- (void)textFieldDidEndEditing:(UITextField *)textField
{
[self animateTextField: textField up: NO];
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
[textField resignFirstResponder];
return YES;
}
I think you forgot to set the delegate for text field which you can set as
_firstRoommateTextField.delegate = self;
_secondRoommateTextField.delegate = self;
in viewDidLoad
or from storyBoard
ctrl+drag from textField to ViewController (right top just below View Controller scene ) and select delegate .
First check the textfield object is assigned to the delegate..i.e.
_firstRoommateTextField.delegate = self;
_secondRoommateTextField.delegate = self;
and then check your delegate methods are getting called or not.
Finally try this, instead of CGRectOffset, try CGRectMake.

Xcode Outlets No Showing

Im still quite new to Xcode and wonder if someone can point out where Im going wrong with some code I took from a tutorial?
The code is to resize a view and it worked in the tutorial. Ive check numerous times and my code is identical to the tutorial and it builds OK.
The code is below. The trouble Im having is that my outlets aren't showing in the connections inspector - so I can't connect to my storyboard.
Many thanks for any assistance.
h file
#import <UIKit/UIKit.h>
#interface MyViewViewController : UIViewController{
CGRect viewMinRect;
IBOutlet UIView *myView;
}
#end
m file
#import "MyViewViewController.h"
#interface MyViewViewController ()
#end
#define MAX_SIZE CGRectMake(100, 100, 100, 100)
#implementation MyViewViewController
- (void)viewDidLoad
{
[super viewDidLoad];
viewMinRect = myView.bounds;
}
- (void)viewDidUnload{
[super viewDidUnload];
}
- (BOOL)shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation !=UIInterfaceOrientationPortraitUpsideDown);
}
- (IBAction)animateView:(id)sender{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationCurve:UIViewAnimationCurveLinear];
[UIView setAnimationDuration:0.8f];
if(CGRectEqualToRect(myView.bounds, viewMinRect)){
myView.bounds = MAX_SIZE;
myView.alpha = 1.0;
}
else
{myView.bounds = viewMinRect;
myView.alpha = 0.5;
}
[UIView commitAnimations];
}
#end
Is the class of the view in Interface Builder set to MyViewViewController? If not change it to MyViewViewController.

Pop-Up not appearing in iOS

I'm trying to create a simple popup called Add Notes on a button click which has a save and cancel button to save the notes created by the user and to cancel the pop-up. This is pop-up classes
AddNotesPopUp.h
#import <UIKit/UIKit.h>
#import "UIImage+Buttons.h"
typedef enum AddNotesViewType
{
AddNotesPopUpSimple
}AddNotesPopUpType;
#protocol AddNotesDelegate<NSObject>
#optional
-(void)saveButtonClicked:(id) popUp;
-(void)cancelAddButtonClicked:(id)popUp;
#end
#interface AddNotesPopUp : UIView
#property AddNotesPopUpType atype;
#property (nonatomic,assign) id <AddNotesDelegate> delegate;
-(id)initWithDelegate:(id)parent type:(AddNotesPopUpType) type;
#property (weak, nonatomic) IBOutlet UIView *popView;
#property (strong, nonatomic) IBOutlet UIButton *titleButton;
#property (weak, nonatomic) IBOutlet UIButton *cancelAddButton;
#property (weak, nonatomic) IBOutlet UIButton *saveButton;
#property (weak, nonatomic) IBOutlet UITextView *textArea;
- (IBAction)saveButtonAction:(id)sender;
- (IBAction)cancelButtonAction:(id)sender;
-(void)show;
-(void)hide;
#end
AddNotesPopUp.m
#import "AddNotesPopUp.h"
#import <QuartzCore/QuartzCore.h>
#implementation AddNotesPopUp
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
self=(AddNotesPopUp*)[[[NSBundle mainBundle] loadNibNamed:#"AddNotesPopUp" owner:nil options:nil] lastObject];
}
return self;
}
-(id)initWithDelegate:(id)parent type:(AddNotesPopUpType) type
{
if (self = [super initWithFrame:CGRectMake(0, 0, 300, 300)])
{
// Initialization code
self=(AddNotesPopUp*)[[[NSBundle mainBundle] loadNibNamed:#"AddNotesPopUp" owner:nil options:nil] lastObject];
}
self.delegate=parent;
self.atype=type;
UIViewController *parentView=(UIViewController*)parent;
[parentView.view addSubview:self];
if (type==AddNotesPopUpSimple)
{
[self.titleButton setImage:[UIImage buttonWithText:#"Add Notes" fontSize:15 bold:YES buttonSize:self.titleButton.frame.size baseColor:[UIColor colorWithRed:73.0/255.0 green:90.0/255.0 blue:100.0/255.0 alpha:1] downTo:[UIColor colorWithRed:57.0/255.0 green:70.0/255.0 blue:77.0/255.0 alpha:1]] forState:UIControlStateNormal];
[self.saveButton setImage:[UIImage buttonWithTextAlignCenter:#"Save" fontSize:15 bold:YES buttonSize:self.saveButton.frame.size baseColor:[UIColor colorWithRed:117.0/255.0 green:185.0/255.0 blue:83.0/255.0 alpha:1] downTo:[UIColor colorWithRed:95.0/255.0 green:144.0/255.0 blue:64.0/255.0 alpha:1]] forState:UIControlStateNormal];
[self.cancelAddButton setImage:[UIImage buttonWithTextAlignCenter:#"Cancel" fontSize:15 bold:YES buttonSize:self.cancelAddButton.frame.size baseColor:[UIColor colorWithRed:174.0/255.0 green:174.0/255.0 blue:174.0/255.0 alpha:1] downTo:[UIColor colorWithRed:124.0/255.0 green:124.0/255.0 blue:124.0/255.0 alpha:1]] forState:UIControlStateNormal];
}
self.popView.layer.masksToBounds=YES;
self.popView.layer.cornerRadius=5.0f;
self.popView.layer.borderWidth=1.0f;
self.popView.layer.borderColor=[[UIColor blackColor]CGColor];
self.popView.hidden=YES;
self.hidden=YES;
self.textArea.hidden=YES;
return self;
}
-(void)show
{
self.popView.hidden=NO;
self.textArea.hidden=NO;
[self.popView setTransform:CGAffineTransformMakeScale(0.1,0.1)];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.25];
[self.popView setTransform:CGAffineTransformMakeScale(1.0,1.0)];
[UIView commitAnimations];
}
-(void) hide
{
self.popView.hidden=YES;
}
- (IBAction)saveButtonAction:(id)sender {
[self.delegate saveButtonClicked:self];
}
- (IBAction)cancelButtonAction:(id)sender {
[self.delegate cancelAddButtonClicked:self];
}
#end
This is how I call the popup in my viewcontroller button action
- (IBAction)addNotes:(id)sender {
AddNotesPopUp *pop=[[AddNotesPopUp alloc] initWithDelegate:self type:AddNotesPopUpSimple];
[pop show];
}
I have checked with breakpoints and the execution goes successfully through the initwithDelegate and show methods in AddNotesPopUp.m but the pop-up doesnt appears, what am I missing here? I have added the delegates and classes of AddNotesPopUp in my viewcontroller and I dont receive any error either. I'm using Xcode 4.6. Any Suggestions?
Turns out it was a simple issue, I just needed to add
self.hidden=NO; in the show method

Resources