Xcode 7.3.1 Working with iAd Bannerviews Objective-C - ios

After following countless tutorials and trying different methods, my iAd banners simply do not show while running the simulation, and if they do, they fade quickly without displaying anything.
This is the current code I am using to display an iAd banner:
-(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]; }
I have delegated the banner to the view, have imported the iAd framework in the viewcontroller.h, and followed all other necessary steps. However, while launching the simulator (in any phone size) an ad does not appear, even after waiting a considerable amount of time. I have no errors or other indications that I have done something wrong, and have been stuck on this for a while. Why won't the banner show?

Related

Placing iAd over UITabBar in a UITableView, Objective-C & TableView not appearing beneath iAd

I am trying to get a similar result to the post that is shown here: https://stackoverflow.com/questions/28866171/place-iad-over-a-uitabbar
So this is what i did to achieve this:
One side question here: Is it normal that i can't drag the banner all the way?
And using this i get this result:
Nevermind that the iAd dont show. But my real question is why is not the TableView appearing beneath the iAd so i can get the same result as the on in the post? What can i do to make this work?
Thank you all!
Ok i solved this with some more researching and testing.
FIRST OF ALL. You DONT need to use a UITableView inside a UIViewController to make this work. This can be done by having a subclass of UITableViewController which i had from start but i thought i needed to change.
Anyway Here is the code:
- (void)viewDidLoad
{
[super viewDidLoad];
self.canDisplayBannerAds = YES;
}
- (void)bannerViewDidLoadAd:(ADBannerView *)banner
{
banner.frame = CGRectOffset(banner.frame, 0, banner.frame.size.height);
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1];
[banner setAlpha:1];
[UIView commitAnimations];
}
- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error
{
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1];
[banner setAlpha:0];
[UIView commitAnimations];
}
NOTE this method is used when i am not placing an iAd in the storyboard. There is no need to do that when using this method. So no need to think about putting delegates etc..

iAd banner doesn't reappear after navigation controller pop

I'm running into a problem with my iAd banner view. Initially I have a main menu when my app first loads up. I have an iAd Banner positioned right off the bottom edge of the view and it is animated to appear once my view appears. When I press a button to push to another view controller in the navigation controller hierarchy and then press back to return to the main menu, the iAd does not reappear.It only shows up again when I completely restart the app.
Here is my code:
//MainMenu. h
#property (strong, nonatomic) IBOutlet ADBannerView *adView;
#property (nonatomic) BOOL bannerIsVisible;
//MainMenu.m
-(void)viewWillAppear:(BOOL)animated
{
bannerIsVisible = NO;
adView.delegate = self;
[self.navigationController setNavigationBarHidden: YES animated:YES];
}
#pragma Begin Ad View Methods
-(void)bannerViewDidLoadAd:(ADBannerView *)banner
{
if(bannerIsVisible == NO)
{
NSLog(#"Banner ad loaded");
[UIView beginAnimations:#"animateAdBannerOn" context:NULL];
banner.frame = CGRectOffset(banner.frame, 0, -banner.frame.size.height);
[UIView commitAnimations];
bannerIsVisible = YES;
}
}
-(void)viewWillDisappear:(BOOL)animated
{
if(bannerIsVisible == YES)
{
[UIView beginAnimations:#"animateBannerOff" context:NULL];
adView.frame = CGRectOffset(adView.frame, 0, adView.frame.size.height);
[UIView commitAnimations];
bannerIsVisible = NO;
}
}
-(void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error
{
NSLog(#"Failed to load the ad in main menu: %#", [error localizedDescription]);
}
#pragma End Ad View Methods
I've tried removing the offset methods and just turning the adView.hidden = YES/NO to see if it was an animation problem but the result is the same. If anyone could offer tips or help it would be greatly appreciated. I've also tried putting the respective code in other methods like viewDidLoad and viewDidDisappear too.
It is something,
just on your main view, add a View of type UIView, give it a size respecting the size of the add you want to have,
then instead of loading your ads in the main view, load it in the view you added specifically for the banner

UIWebthreadlock freezes app

I have a view in wich I present two different uiwebviews (loaded from local html). Everytime the user taps a button located in the navigation bar, I switch from one webview to another with a page curl animation (curl up and curl down). Everything seems to work fine but sometimes the app freezes when the user tap that button. In most cases the app freezes when I tap the button repeteadly until the app freezes, then I pause the debug and I get this:
self.navigationItem.titleView.userInteractionEnabled = NO; //Disable button interaction until animation is finished
if (self.isVisibleFrontView)
{
self.isVisibleFrontView = NO;
[UIView transitionWithView:self.view
duration:0.5
options:UIViewAnimationOptionTransitionCurlUp | UIViewAnimationOptionCurveEaseInOut
animations:^{
[[[self.view subviews] objectAtIndex:0] removeFromSuperview];
[self.view addSubview:self.patientViewReverse];
}
completion:^(BOOL finished){
self.navigationItem.titleView.userInteractionEnabled = YES;
}];
}
else
{
self.isVisibleFrontView = YES;
[UIView transitionWithView:self.view
duration:0.5
options:UIViewAnimationOptionTransitionCurlDown | UIViewAnimationOptionCurveEaseInOut
animations:^{
[[[self.view subviews] objectAtIndex:0] removeFromSuperview];
[self.view addSubview:self.patientView];
}
completion:^(BOOL finished){
self.navigationItem.titleView.userInteractionEnabled = YES;
}];
}
[self showNavigationBarButtons]; //change button image
}
I think webView is acquiring lock when removeFromSuperview but in some cases never release it, resulting in a main thread freeze. What do you think? What is the best approach to achieve this without freezing the app?
Thanks in advance guys.
Finally I've fixed it.
Now all I do is setHidden:YES the webview I don't want to show and setHidden:NO the other webview in the animation block instead of removing and adding as subviews the webviews each time. This is more efficient and the webview doesn't use the webthreadlock.

iPad orientation notifications lost when transition for keyWindow

I have an animation done over the keyWindow of the app.
[UIView beginAnimations:kAnimationLogin context:nil];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:window_ cache:NO];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:1.0];
[window_ addSubview:splitViewController_.view];
[UIView commitAnimations];
[loginViewController_.view removeFromSuperview];
This works ok. Then, if the user logouts, the transition is the reverse
[UIView beginAnimations:kAnimationLogout context:nil];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:window_ cache:NO];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:1.0];
[window_ addSubview:loginViewController_.view];
[UIView commitAnimations];
[splitViewController_.view removeFromSuperview];
Here is the problem. Now, loginViewController_ and splitViewController_ don't receive the orientation notifications. Why?
Well, it's not a great solution but I've found a way to avoid that problem. First of all, I think that the problem comes because, while animation, both view controllers receives the orientation notifications while, I guess, adding and removing to and from the window and raises the problem. I don't know exactly if it's an issue related to view hierarchy (I guess it's correct but I'm not sure) or not.
So, the solution I use is to put the LoginViewController as a ModalViewController of SplitViewController, that is the main controller, and use a FlipHorizontal transition while showing.
That solves the problem.

conceptual or technical issue with Cocoa programming

I find myself in need of access to a viewcontroller from its view.
Here is the method
-(void)changePageView:(UIViewController*)newviewcont withtransitiontype:(int)t andtransitionspeed:(int)s
{
//Remove whatever view is currently loaded at index 0, this index is only to be used by "page" views
UIView *oldview = [self.view.subviews objectAtIndex:0];
[UIView beginAnimations:#"View Flip" context:nil];
[UIView setAnimationDuration:s];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.view cache:YES];
[newviewcont viewWillAppear:YES];
//[oldview viewWillDisappear:YES];
[oldview removeFromSuperview];
[self.view insertSubview:newviewcont.view atIndex:0];
//[oldview viewDidDisappear:YES];
[newviewcont viewDidAppear:YES];
}
Basically, I am trying to write a generic view switch method that is called by the root controller to swap out subviewcontorllers views from the rootcontrollers view.
I pass in a subviewcontroller and am able to remove the current subview. But in order to do proper view switching animation i need access to the current views view controller. Is this the wrong approach and can it be done?
I added a member to the rootcontroller that hold onto the current sub view controller (currentController) and refers to it when a controller swap is done
-(void)changePageView:(UIViewController*)newviewcont withtransitiontype:(int)t andtransitionspeed:(int)s
{
[UIView beginAnimations:#"View Flip" context:nil];
[UIView setAnimationDuration:s];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.view cache:YES];
[newviewcont viewWillAppear:YES];
[self.currentController viewWillDisappear:YES];
[self.currentController.view removeFromSuperview];
[self.view insertSubview:newviewcont.view atIndex:0];
[self.currentController viewDidDisappear:YES];
[newviewcont viewDidAppear:YES];
[UIView commitAnimations];
self.currentController = newviewcont;
}
The changeView() method belongs in the viewcontroller. It would solve you problem of having the view knowing about it's controller (which it shouldn't) and it makes more sense.
Also unless you are doing something fancy in changeView() that can't be done using the methods in a UIViewController object then you should just use it instead, if it is neccesary to implement your own view switching method then you can extend UIViewController instead of implemtning part of the view controlelr in your view.
my 2 cents :)
I believe your approach is wrong. You should look into UINavigationController I believe.

Resources