iAd get screwed up on ipad simulator - ios

currently I'm trying to implement iAd in my universal iOS7 app.
This is working absolutly fine on iphone but on the ipad i get this screwed up ads but the bannersize is correct.
is this a known issue? or is there a ipad special implementation I didn't knew?
[edit!]
I'm pretty sure there is only one banner! its really just showing the normal iad ad in that weird way.
If I click on the ad, the fullscreen one is also not right scaled but its shown on the hole screen. Here is my implementation:
- (void)viewDidLoad
{
_adBannerView = [[ADBannerView alloc] initWithAdType:ADAdTypeBanner];
_adBannerView.delegate = self;
_bannerIsVisible = NO;
[self.view addSubview:self.adBannerView];
...
}
- (void)viewDidLayoutSubviews {
CGRect contentFrame = _mainNavigation.frame, bannerFrame = CGRectZero;
bannerFrame.size = [_adBannerView sizeThatFits:contentFrame.size];
if (_adBannerView.bannerLoaded && !_bannerIsVisible) {
contentFrame.size.height -= bannerFrame.size.height;
bannerFrame.origin.y = contentFrame.origin.y + contentFrame.size.height;
_bannerIsVisible = YES;
} else {
bannerFrame.origin.y = contentFrame.origin.y + contentFrame.size.height;
}
_mainNavigation.frame = contentFrame;
_adBannerView.frame = bannerFrame;
}
- (void)bannerViewDidLoadAd:(ADBannerView *)banner {
[UIView animateWithDuration:0.25 animations:^{
[self.view setNeedsLayout];
[self.view layoutIfNeeded];
}];
}
- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error {
NSLog(#"didFailToReceiveAdWithError %#", error);
[UIView animateWithDuration:0.25 animations:^{
[self.view setNeedsLayout];
[self.view layoutIfNeeded];
}];
}
And is there a way to show the test ads on a real device?
because I always get "Ad inventory unavailable"!

Related

Send button is not working when keyboard opened in iOS

I am stuck in very simple functionality in iOS.
I am trying to send the data from a textField which is inside the subview of a scroll view. Button is firing the action when I hit the button, when keyboard is closed as soon as I try to write something and keyboard opened button stop responding.
VideoViewController:
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
controller.videoID = videoID;
controller.channelID = channelID;
controller.view.frame = self.commentView.bounds;
[self.commentView addSubview:controller.view];
// [self.scrollView addSubview:controller.sendBtn];
[self addChildViewController:controller];
[controller didMoveToParentViewController:self];
}
CommentViewController:
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
controller.videoID = videoID;
controller.channelID = channelID;
controller.view.frame = self.commentView.bounds;
[self.commentView addSubview:controller.view];
// [self.scrollView addSubview:controller.sendBtn];
[self addChildViewController:controller];
[controller didMoveToParentViewController:self];
}
-(void)keyboardWillShow:(NSNotification *)notification
{
CGSize keyboardSize = [[[notification userInfo] objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;
[UIView animateWithDuration:0.3 animations:^{
CGRect f = self.view.frame;
f.origin.y = -keyboardSize.height+100;
self.sendView.frame = f;
}];
_sendBtn.userInteractionEnabled = YES;
}
-(void)keyboardWillHide:(NSNotification *)notification
{
[UIView animateWithDuration:0.3 animations:^{
CGRect f = self.view.frame;
f.origin.y = 0.0f;
self.sendView.frame = f;
}];
}
-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
[commentTextField resignFirstResponder];
return YES;
}
- (BOOL)touchesShouldCancelInContentView:(UIView *)view
{
return ![view isKindOfClass:[UIButton class]];
}
Please suggest something on this.
Thank you.
I faced this problem, too
It took me 2 days to find the solution. You need to set the cancel touches flag to false for ScrollVIew/View.
Actually, scrollview touch is enable and it is not allowing the button to interact.
This is the only reason send button is not working.

iAd is white (not loaded) when application starts

My iAd is white. It looks like bannerViewDidLoadAd is run when the iAd is not fully loaded. It happens only when I show my ViewController first time (application starts). When I go to another controller and return, iAd is loaded properly. Do you have any idea why?
- (void)bannerViewDidLoadAd:(ADBannerView *)banner {
_bannerView.hidden = NO;
[self.view setNeedsLayout];
}
- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error {
_bannerView.hidden = YES;
[self.view setNeedsLayout];
}
-(void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
if (!_bannerView) {
_bannerView = [[ADBannerView alloc] initWithAdType:ADAdTypeBanner];
_bannerView.delegate = self;
_bannerView.hidden = YES;
CGRect bannerFrame = _bannerView.frame;
bannerFrame.origin.y = self.view.bounds.size.height - _bannerView.bounds.size.height;
_bannerView.frame = bannerFrame;
[self.view addSubview:_bannerView];
}
}
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
_bannerView.delegate = nil;
[_bannerView removeFromSuperview];
_bannerView = nil;
}

How to remove ADBannerView out from UIViewController in my iOS app?

In my app, I had added the ADBannerView into the UIViewController by code
in .h file
#property (strong, nonatomic) ADBannerView *adBannerView;
in .m file
- (void)viewDidLoad
{
[super viewDidLoad];
self.adBannerView = [[ADBannerView alloc] initWithFrame:CGRectMake(0, 518, 320, 50);];
[self.view addSubview:self.adBannerView];
}
#pragma mark - ADBannerViewDelegate
- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error {
NSLog(#"bannerview did not receive any banner due to %#", error);
}
- (void)bannerViewActionDidFinish:(ADBannerView *)banner {
NSLog(#"bannerview was selected");
}
- (BOOL)bannerViewActionShouldBegin:(ADBannerView *)banner willLeaveApplication:(BOOL)willLeave {
NSLog(#"banner action should begin");
return YES;
}
- (void)bannerViewWillLoadAd:(ADBannerView *)banner {
NSLog(#"banner will loaded");
}
- (void)bannerViewDidLoadAd:(ADBannerView *)banner {
NSLog(#"banner was loaded");
}
My app is normally, it can show the ADBannerView. But now, I want to remove the ADBannerView out of the UIViewController, then I removed all the lines of code about the ADBannerView. I can build my app, but it cannot run, the error msg is:
Could not instantiate class named ADBannerView
Please help me to remove the ADBannerView. Thank you.
- (void)bannerViewDidLoadAd:(ADBannerView *)banner{
if (!bannerIsVisible){
//LOG_TYPE(#"AD show");
[UIView beginAnimations:#"animateAdBannerOn" context:NULL];
// banner is invisible now and moved out of the screen on 50 px
// banner.frame = CGRectOffset(banner.frame, 0, -50);
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone){
if (IS_IPHONE_5) {
//LOG_TYPE(#"view height: %f",self.view.bounds.size.height);
self.adView.frame = CGRectMake(0,568-49-50, self.view.frame.size.width, 50);
}
else{
//LOG_TYPE(#"view height: %f",self.view.bounds.size.height);
self.adView.frame = CGRectMake(0,480-49-50, self.view.frame.size.width, 50);
}
}
else{
self.adView.frame = CGRectMake(0,1024-56-50, self.view.frame.size.width, 50);
}
[UIView commitAnimations];
bannerIsVisible = YES;
[self performSelector:#selector(hideAD) withObject:nil afterDelay:6];
}
}
- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error{
if (bannerIsVisible){
//LOG_TYPE(#"AD error");
[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, 50);
bannerIsVisible = NO;
[self performSelector:#selector(hideAD) withObject:nil afterDelay:0];
// [self performSelector:#selector(hideAD) withObject:nil afterDelay:5];
}
}
- (BOOL)bannerViewActionShouldBegin:(ADBannerView *)banner willLeaveApplication:(BOOL)willLeave{
//LOG_TYPE(#"Banner view is beginning an ad action");
BOOL shouldExecuteAction = YES;
if (!willLeave && shouldExecuteAction){
// stop all interactive processes in the app
// [video pause];
// [audio pause];
}
return shouldExecuteAction;
}
- (void)bannerViewActionDidFinish:(ADBannerView *)banner{
// resume everything you've stopped
// [video resume];
// [audio resume];
}
- (void)hideAD{
//LOG_TYPE(#"Hide AD");
[UIView beginAnimations:#"animateAdBannerOff" context:NULL];
// banner is visible and we move it out of the screen, due to connection issue
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone){
if (IS_IPHONE_5) {
//LOG_TYPE(#"view height: %f",self.view.bounds.size.height);
self.adView.frame = CGRectMake(0,568-49+50, self.view.frame.size.width, 50);
}
else{
//LOG_TYPE(#"view height: %f",self.view.bounds.size.height);
self.adView.frame = CGRectMake(0,480-49+50, self.view.frame.size.width, 50);
}
}
else{
self.adView.frame = CGRectMake(0,1024-56+50, self.view.frame.size.width, 50);
}
[UIView commitAnimations];
bannerIsVisible = NO;
[self performSelector:#selector(bannerViewDidLoadAd:) withObject:self.adView afterDelay:60];
}
-(void)viewDidLoad{
...
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone){
if (IS_IPHONE_5) {
self.adView = [[ADBannerView alloc] initWithFrame:CGRectMake(0,568-49-50, self.view.frame.size.width, 50)];
}
else{
self.adView = [[ADBannerView alloc] initWithFrame:CGRectMake(0,480-49-50, self.view.frame.size.width, 50)];
}
}
else{
self.adView = [[ADBannerView alloc] initWithFrame:CGRectMake(0,1024-56-50, self.view.frame.size.width, 50)];
}
[self.view addSubview:self.adView];
self.adView.delegate=self;
bannerIsVisible=NO;
self.adView.backgroundColor = [UIColor clearColor];
....
}
if you add ADBannerView in storyboard then remove the IBoutlet of ADBannerView and its delegate.
break connection of below figure for ADBannerView
remove ADBannerViewfrom storyboard and your above code is perfect.
Your error as below.
[self.adView removeFromSuperView];

Why does iAd banner interferes with my UIView animations

I have an iAd that I created following this tutorial and for some reason when the iAd shows-up any animation going on at that time stops. In other words the animations work fine until the iAd apears and as soon as the iAd apears any animation going at that moment stops or it goes back to its original position without finishing the animation.
This is the code I have for the iAd
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
_adBanner = [[ADBannerView alloc] initWithFrame:CGRectMake(0, self.view.frame.size.height, 320, 50)];
_adBanner.delegate = self;
}
- (void)bannerViewDidLoadAd:(ADBannerView *)banner
{
if (!_bannerIsVisible)
{
if (_adBanner.superview == nil)
{
[self.view addSubview:_adBanner];
}
[UIView beginAnimations:#"animateAdBannerOn" context:NULL];
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:#"animateAdBannerOff" context:NULL];
banner.frame = CGRectOffset(banner.frame, 0, banner.frame.size.height);
[UIView commitAnimations];
_bannerIsVisible = NO;
}
}
And this is one of the animations I have
- (IBAction)showHideBlackboard:(id)sender
{
[UIView animateWithDuration:0.6 delay: 0.0 options: UIViewAnimationOptionCurveEaseIn animations:^
{
self.controlsView.frame= CGRectMake(10, 10, 250, 250);
}completion:^(BOOL finished)
{
[UIView animateWithDuration:0.6 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^
{
self.drawingView.alpha = 1.0;
self.drawingView.frame= CGRectMake(10, 10, 350, 350);
}completion:nil ];
}];
}
Any idea why does the iAd interferes with UIView animations?
I recently had a similar problem. It turned out that avoiding the option
self.translatesAutoresizingMaskIntoConstraints = NO;
in my UIView subclass solved the problem.

2 iAds on simulator

I am trying to create 2 iAds but I have only one on simulator. I can not now check it with device. Why I have only one? I have only second iAd
My code is:
adView1 = [[ADBannerView alloc] initWithAdType:ADAdTypeBanner];
adView1.frame = CGRectOffset(adView1.frame, 0, 50);
adView1.delegate = self;
[self.backgroundView addSubview:adView1];
adView2 = [[ADBannerView alloc] initWithAdType:ADAdTypeBanner];
adView2.frame = CGRectOffset(adView2.frame, 0, 200);
adView2.delegate = self;
[self.backgroundView addSubview:adView2];
- (void)bannerViewDidLoadAd:(ADBannerView *)banner
{
if (!self.bannerIsVisible)
{
[UIView beginAnimations:#"animateAdBannerOn" context:NULL];
// banner is invisible now and moved out of the screen on 50 px
if (banner == adView1)
{
banner.frame = CGRectOffset(banner.frame, 0, 50);
}
if (banner == adView2)
{
banner.frame = CGRectOffset(banner.frame, 0, 200);
}
[UIView commitAnimations];
self.bannerIsVisible = YES;
}
}
(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, -50);
[UIView commitAnimations];
self.bannerIsVisible = NO;
}
}
(BOOL)bannerViewActionShouldBegin:(ADBannerView *)banner willLeaveApplication:(BOOL)willLeave
{
NSLog(#"Banner view is beginning an ad action");
BOOL shouldExecuteAction = YES;
if (!willLeave && shouldExecuteAction)
{
[audio pause];
}
return shouldExecuteAction;
}
(void)bannerViewActionDidFinish:(ADBannerView *)banner
{
[audio resume];
}
adView1.frame = CGRectOffset(adView2.frame, 0, 50);
It must be CGRectOffset(adView1.frame, 0, 50); since adView2 is allocation in the next line only???
When you are creating first view, you are using second view's frame:
adView1 = [[ADBannerView alloc] initWithAdType:ADAdTypeBanner];
adView1.frame = CGRectOffset(adView2.frame, 0, 50);
adView1.delegate = self;
[self.backgroundView addSubview:adView1];
As adView2 is not created yet - it is nil and frame is (0,0,0,0)
You have to use adView1 frame for offset as you do for second view.
Also, keep in mind that displaying 2 banners is going against Apple guideline and not recommend. Take a look here (Best practices section)
https://developer.apple.com/library/ios/documentation/userexperience/conceptual/iAd_Guide/WorkingwithBannerViews/WorkingwithBannerViews.html

Resources