Problems with iAds and iOS 8 - objective-c

When I run my app on iOS 7, all iAds works like a charm in every view controllers. But when i run my app on iOS 8 and navigate around the app when i return to main view or maybe in other view before charged, the iAds shows blank. I've tried all types of code, and with all of them have the problem.
- (void)viewDidAppear:(BOOL)animated{
[super viewDidAppear:animated];
if (!_adBanner) {
_adBanner = [[ADBannerView alloc] initWithFrame:CGRectMake(0, self.view.bounds.size.height, 320, 50)];
[_adBanner setBackgroundColor:[UIColor clearColor]];
[self.view addSubview:_adBanner];
}
_adBanner.delegate = self;}
-(void)viewDidDisappear:(BOOL)animated{
[super viewDidDisappear:animated];
_adBanner.delegate=nil;
}
//delegates
-(void)bannerViewDidLoadAd:(ADBannerView *)banner{
if (!_bannerIsVisible /*&& _original*/) {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1];
[_adBanner setAlpha:1];
banner.frame = CGRectOffset(banner.frame, 0, -banner.frame.size.height);
[UIView commitAnimations];
_bannerIsVisible = YES;
}
}
-(void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error
{
if (_bannerIsVisible) {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1];
[_adBanner setAlpha:0];
banner.frame = CGRectOffset(banner.frame, 0, banner.frame.size.height);
[UIView commitAnimations];
_bannerIsVisible = NO;
}
NSLog(#"%#",error);
}
And in console get this error: "Error Domain=ADErrorDomain Code=7 "The operation couldn’t be completed. Ad was unloaded from this banner" UserInfo=0x7a698c20 {ADInternalErrorCode=7, ADInternalErrorDomain=ADErrorDomain, NSLocalizedFailureReason=Ad was unloaded from this banner}"

I am having exactly the same issue and I want to post an answer here which doesn't solve it in my case (so please accept that THIS IS NOT AN ACTUAL answer) but I wanted to provide a few details that I can't do in a comment.
I'm having the exact same issue with switching between views in a UITabBarController and when I come back to the first view, the AdBannerView is there, but doesn't actually show any ads for 1 minute, even though the delegate methods are being run.
I firstly went and followed this guide (https://www.youtube.com/watch?v=_0Mv44FWw0A&feature=youtu.be) on how to set up Shared instances of AdBannerViews which may or may not be what you're doing, but this could help; you never know.
In my case, that didn't do anything.
But I did implement viewWillDisappear:
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
self.adBanner.delegate = nil;
self.adBanner = nil;
[self.adBanner removeFromSuperview];
}
If I comment out that code, I receive the same error you're facing in the console, with Error Code 7. If I don't comment out that code, I get through without any errors (i.e the didFailToReceiveAdWithError never gets run).
However, the issue I'm facing is that when I come back to the view from another tab, the viewWillAppear gets run, followed instantly by the bannerViewDidLoadAd, but that doesn't actually bring in the ad for 1 minute and instead I'm left with a blank white banner.
Also, I'm running the loading code from the viewWillAppear (because this gets called every time you come back to this ViewController, instead of viewDidLoad.
self.adBanner = [[self appdelegate] adBanner];
self.adBanner.delegate = self;
[self.adBanner setFrame:CGRectMake(0, 101, 320, 580)];
[self.view addSubview:self.adBanner];
I'm not sure if this will help. I hope it does and if it does, perhaps we can work together to understand why mine doesn't work on iOS 8, either!

Related

Strange controls animation after transitionWithView

I am trying to transition from one view to another.
The final view I'm transitioning to is a XIB with a couple buttons and a title bar.
My problem is that after the transition, the buttons get displayed on the very top left of the window for a fraction of a second, and eventually "drag" to their expected coordinates. Everything is perfectly usable and functional, but the transition looks a little funny.
Any idea what could cause this?
Here is my code snipet:
Homepage *hp = [[Homepage alloc] init];
hp.data = self.data;
[UIView transitionWithView:self.view duration:0.5
options:UIViewAnimationOptionTransitionCurlDown
animations:^ { [self.view addSubview:hp.view]; }
completion:nil];
[hp DisplayThumbnails];
[hp release];
I wanted to provide the code snippet that I've used to resolve this problem using Jacob's recommendation in case someone else runs into this. Here it is:
Homepage *hp = [[Homepage alloc] init];
hp.data = self.data;
[hp.view setHidden:YES];
[self.view addSubview:hp.view];
[UIView transitionWithView:self.view duration:0.5
options:UIViewAnimationOptionTransitionCurlDown
animations:^ { [hp.view setHidden:NO];}
completion:nil];
[hp DisplayThumbnails];

Simple UIView animation move doesn't work

I have no idea, why it is not working.
All I want to do is a simple UIView animation in the viewDidLoad.
Here's my code:
[UIView animateWithDuration:3.0f animations:^{
[self.headline setCenter:CGPointMake(0.0, 200.0)];
}];
Nothing happens. When I test the general approach of calling a animation method on that particular object like this:
[UIView animateWithDuration:3.0f animations:^{
[self.headline setAlpha:0.0];
}];
it works!!! Why am I not able to move the view across the screen? I am using latest Xcode 4.5.
Thanks for any advice!
UPDATE:
When I add a view manually in code it works. But for the UIViews I create as Outlets in the Interface Builder it doesn't work.
UILabel *testLabel = [[UILabel alloc] initWithFrame:CGRectMake(0.0, 0.0, 200.0, 100.0)];
testLabel.backgroundColor = [UIColor redColor];
[self.view addSubview:testLabel];
[UIView animateWithDuration:3.0 animations:^{
testLabel.center = CGPointMake(0.0, 200);
}];
So obviously I am doing something wrong in the .xib file
Dont do it in viewDidLoad. The view is not pressent at that time yet.
Try it in viewDidAppear.
Well, I think the reason for the missing animation was the fact that I called a different push navigation animation from the view controller that was pushing the actual view on screen:
- (IBAction)goForSelection:(id)sender
{
SelectionViewController *selectionViewController = [[SelectionViewController alloc] initWithNibName:#"SelectionViewController" bundle:nil];
//[self.navigationController pushViewController:selectionViewController animated:YES];
[UIView transitionWithView:self.navigationController.view duration:1.0 options:UIViewAnimationOptionTransitionFlipFromRight animations:^{
[self.navigationController pushViewController:selectionViewController animated:NO];
} completion:^(BOOL finished) {
[selectionViewController startIntroAnimation];
}];
}
First I checked what happens when I use the default navigation controller segue. And to my surprise the animation did start. Then I inserted the call to the [selectionViewController startIntroAnimation] to the completion block and this works as well.

Extending a view to the left side, animated

I have a view that I want to extend on the left side using an animation. All borders but the left one should remain the same, so the x position and the width of the view are changing.
I use this code:
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:5.0];
self.frame = CGRectMake(self.frame.origin.x-100,
self.frame.origin.y,
self.frame.size.width+100,
self.frame.size.height);
[UIView commitAnimations];
If I run this code, the width of the view is set to the new value immediately and then the view is moved to the new x point, but why? How can I change this behaviour?
Thanks for your ideas!
Your code runs fine for me. How are you running it? Calling -setFrame is the right choice for what you're doing. Here is what my custom view looks like:
#import "TestView.h"
#implementation TestView
- (id)initWithFrame:(CGRect)frame {
if ((self = [super initWithFrame:frame])) {
// Initialization code
}
return self;
}
- (void)dealloc {
[super dealloc];
}
- (void)go;
{
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:5.0];
self.frame = CGRectMake(self.frame.origin.x-100,
self.frame.origin.y,
self.frame.size.width+100,
self.frame.size.height);
[UIView commitAnimations];
}
#end
I create an outlet from my view controller of type TestView and connect it and set its type in IB. Then I create a button whose handler calls [customView go]; Seems to work fine.
Okay, I made it woring now. The problem was that my view was a UIButton and I set the title and background with the setBackground:forState: and setTitle:forState:.
It seems that the background of the view is not animatable. I use the work around that I add my own background with a UIImageView.
Thanks for your replies!

Strange graphics glitch when using flip animation

I'm getting a strange error when committing a flip animation. These three bars show up, almost like strips that aren't being drawn too.
I got a screenshot to show what I'm talking about. These lines are always in the same place, and show up on both sides.
graphics glitch screenshot http://img263.imageshack.us/img263/6079/animationglitch.jpg
Here is the code that I'm using, I've used it before without problems, so I'm not sure whats goin on.
-(void)switchView
{
BOOL isChangingToMapView = _mapViewController.view.superview == nil;
CGContextRef context = UIGraphicsGetCurrentContext();
[UIView beginAnimations:nil context:context];
[UIView setAnimationDuration:1];
[UIView setAnimationTransition:(isChangingToMapView ? UIViewAnimationTransitionFlipFromLeft : UIViewAnimationTransitionFlipFromRight) forView:self.view cache:YES];
if (isChangingToMapView)
{
[_mapViewController viewWillAppear:YES];
[_listViewController viewWillDisappear:YES];
[_listViewController.view removeFromSuperview];
[self.view insertSubview:_mapViewController.view atIndex:0];
[_listViewController viewDidDisappear:YES];
[_mapViewController viewDidAppear:YES];
}
else
{
[_listViewController viewWillAppear:YES];
[_mapViewController viewWillDisappear:YES];
[_mapViewController.view removeFromSuperview];
[self.view insertSubview:_listViewController.view atIndex:0];
[_mapViewController viewDidDisappear:YES];
[_listViewController viewDidAppear:YES];
}
[UIView commitAnimations];
}
Any ideas as to what could be causing this?
Well I banged my head off of this problem for awhile and then moved on. Then I had the bright idea to try it on the actual phone. Sure enough it runs properly on the phone.
Just a little reminder, if you are having weird problems developing on the simulator, at least try your app on the phone before you waste to much time chasing a bug made by the simulator.

getting a view controller to disappear

I'm trying out a multiple view application, but I can't seem to get the first view controller to go away when I bring in the new view controller. I'm laying the second (coming) view controller at index 0, and it's just placing it in the background. I thought the [going.view removeFromSuperview] would remove the original viewcontroller, but that's not what is happening...
UIViewController *coming = nil;
UIViewController *going = nil;
UIViewAnimationTransition transition;
if (answer == YES)
{
coming = boyController;
going = getInfoController;
transition = UIViewAnimationTransitionFlipFromLeft;
}
else
{
coming = girlController;
going = getInfoController;
transition = UIViewAnimationTransitionFlipFromLeft;
}
NSLog(child);
[UIView setAnimationTransition:transition forView: self.view cache:YES];
[coming viewWillAppear:YES];
[going viewWillDisappear:YES];
[going.view removeFromSuperview];
[self.view insertSubview:coming.view atIndex:0];
[going viewDidDisappear:YES];
[coming viewDidAppear:YES];
[UIView commitAnimations];
First a little refactoring:
coming = (answer ? boyController : girlController);
You can delete going and transition, as they're only used once. Then, to actually do the animation, you need to put everything in the context of an animation block.
[UIView beginAnimations:#"flipAnimation" context:NULL];
[UIView setAnimationTransition:transition forView:self.view cache:YES];
[getInfoController.view removeFromSuperview];
[self.view addSubview:coming.view];
[UIView commitAnimations];
viewWillAppear: and viewWillDisappear: are delegate methods. These will be called automatically on those views' delegates, if any. They shouldn't ever be called manually.