didFailToReceiveAdWithError不工作为iOS 8模拟器模拟器、工作、didFailToReceiveAdWithError、iOS

2023-09-08 15:45:21 作者:我说为爱你不够勇敢

我的IAD / AdMob的调解工作正常与所有的iOS 7模拟器和设备。但是,iOS的8 didFailToReceiveAdWithError方法不适用于任何模拟器的工作,但它适用于iOS的8个设备。问题是我没有一个iPhone六月六日+设备进行测试。所以我依靠的iOS 8模拟器。

   - (无效)bannerViewDidLoadAd:(ADBannerView *)旗帜{
     [UIView的beginAnimations:无背景:NULL];
     iAd.frame = CGRectOffset(iAd.frame 0,-667);
     [UIView的commitAnimations];

     [UIView的beginAnimations:无背景:NULL];
     iAd.frame = CGRectOffset(iAd.frame 0,0);
     [UIView的commitAnimations];
}

 - (无效)bannerView:(ADBannerView *)的旗帜didFailToReceiveAdWithError:(NSError *)错误{
     [UIView的beginAnimations:无背景:NULL];
     iAd.frame = CGRectOffset(iAd.frame 0,-740);
     [UIView的commitAnimations];

     [UIView的beginAnimations:无背景:NULL];
     AdMob.frame = CGRectOffset(iAd.frame 0,-667);
     [UIView的commitAnimations];
}
 

我甚至不知道,如果didFailToReceive坐标是正确的,因为我没有办法测试。我不明白为什么didFailToReceiveAdWithError不会被调用为iOS只有8模拟器?这是一个iOS的8模拟器bug或者是有什么我可以做些什么来解决这个问题?

//忽略^^

   - (AppDelegate中*)的appdelegate {
  返程(AppDelegate中*)[[UIApplication的sharedApplication]委托]
  }


   - (无效)viewWillAppear中:(BOOL)动画{

   //的iAD

   _iAdView = [[自我的appdelegate] iAdView]。
   _iAdView.delegate =自我;

   screenBounds = [[UIScreen mainScreen]界限];

   [_iAdView的setFrame:CGRectMake(0,0,_iAdView.bounds.size.width,_iAdView.bounds.size.height)];

   _iAdView.center = CGPointMake(screenBounds.size.width / 2,screenBounds.origin.y +(_iAdView.bounds.size.height / 2));

   [self.view addSubview:_iAdView]。



   // AdMob的

   _adMobView = [[自我的appdelegate] adMobView]。

  _adMobView = [[GADBannerView页头] initWithAdSize:kGADAdSizeSmartBannerPortrait]。

  _adMobView.adUnitID = @我的单位-ID;

 _adMobView.rootViewController =自我;

 GADRequest *请求= [GADRequest请求]

 request.testDevices = @ [@测试号];

 [_adMobView loadRequest:申请];

 [_adMobView的setFrame:CGRectMake(0,0,_adMobView.bounds.size.width,_adMobView.bounds.size.height)];

 _adMobView.center = CGPointMake(screenBounds.size.width / 2,screenBounds.size.height  - (_adMobView.bounds.size.height / 2));

 [self.view addSubview:_adMobView]。

 }


  - (无效)viewWillDisappear:(BOOL)动画{//不管我删除此与否,没有什么变化

 //的iAD

 _iAdView.delegate =零;
 _iAdView =零;

 _iAdView.alpha = 0.0;


  // AdMob的

   _adMobView.delegate =零;
   _adMobView =零;

   _adMobView.alpha = 0.0;
   }


    - (无效)bannerViewDidLoadAd:(ADBannerView *)旗帜{

    的NSLog(@的iAd获得了);

    _iAdView.alpha = 1.0;
    _adMobView.alpha = 0.0;

    [UIView的commitAnimations];
    }


     - (无效)bannerView:(ADBannerView *)的旗帜didFailToReceiveAdWithError:(NSError *)错误{

    的NSLog(@iAd的失败,AdMob的获得);

   _iAdView.alpha = 0.0;
   _adMobView.alpha = 1.0;

   [UIView的commitAnimations];
   }
 

解决方案 理财规划, 理 的究竟是什么

这是需要实现的iAd和AdMob横幅一切。它有利于网络成瘾与显示AdMob广告条幅,如果我们的应用程序没有收到来自iAd的广告。我已经看到了很多有关这在过去几个星期,所以我已经从字面上注释掉了尽可能多的问题,我可以帮助大家了解究竟是什么回事。

  //导入的iAd和AdMob在你的头文件
#进口ViewController.h
//输入广告ID从收到的AdMob这里
#定义BANNER_UNIT_ID @yourAdMobBannerID

@interface的ViewController()
@结束

@implementation的ViewController {
    //我们将把这些在这里,所以我们可以在全球访问它们
    GADBannerView * adMobView;
    ADBannerView * iAdView;
    CGRect screenBounds;
}

 - (无效)viewDidLoad中{
    [超级viewDidLoad中]
    //获取设备的屏幕尺寸
    //例如,在iPhone 6 screenBounds看起来像这样
    // screenBounds.origin.x == 0
    // screenBounds.origin.y == 0
    // screenBounds.size.width == 375
    // screenBounds.size.height == 667
    screenBounds = [[UIScreen mainScreen]界限];

    //设置iAd的观点
    //创建AdBannerView
    iAdView = [[ADBannerView页头] initWithFrame:方法CGRectZero]。

    //设置其委托
    iAdView.delegate =自我;

    //这台架原点(0,0),这将是该装置的屏幕的左上角
    // iAdView.bounds.size.width和iAdView.bounds.size.height设置AdBannerView的大小
    [iAdView的setFrame:CGRectMake(0,0,iAdView.bounds.size.width,iAdView.bounds.size.height)];

    //这将需要我们AdBannerView的中心,并将其移动到一个点(X,Y)
    //我们希望在设备屏幕的中心AdBannerView.center
    //所以让我们让我们的屏幕的宽度和除以2就我们这样做是有screenBounds.size.width / 2
    //我们也希望我们的AdBannerView是在屏幕的底部
    //所以,让我们得到我们与screenBounds.size.height屏幕的高度
    //记住这里被谈论我们AdBannerView的中心,因此,如果我们只是将其设置为
    //我们AdBannerView的高度的一半将通过在屏幕的底部被切除
    //因此,让我们AdBannerView的身高减去一半来解决与iAdView.bounds.size.height / 2
    iAdView.center = CGPointMake(screenBounds.size.width / 2,screenBounds.size.height  - (iAdView.bounds.size.height / 2));

    //将它添加到我们的观点
    [self.view addSubview:iAdView]。

    //我们AdBannerView是现在我们的设备屏幕的底部
    //但它需要一秒钟从iAd的网络接收的广告,以便让使它透明的现在
    iAdView.alpha = 0.0;


    //设置AdMob的观点
    //创建GADBannerView
    adMobView = [[GADBannerView页头] initWithAdSize:kGADAdSizeBanner]。

    //使用我们之前定义的BANNER_UNIT_ID
    adMobView.adUnitID = BANNER_UNIT_ID;
    adMobView.rootViewController =自我;
    [adMobView loadRequest:[GADRequest要求];

    //这台架原点(0,0),这将是该装置的屏幕的左上角
    // adMobView.bounds.size.width和adMobView.bounds.size.height设置GADBannerView的大小
    [adMobView的setFrame:CGRectMake(0,0,adMobView.bounds.size.width,adMobView.bounds.size.height)];

    //这将需要我们GADBannerView的中心,并将其移动到一个点(X,Y)
    //我们希望在设备屏幕的中心GADBannerView.center
    //所以让我们让我们的屏幕的宽度和除以2就我们这样做是有screenBounds.size.width / 2
    //我们也希望我们的GADBannerView是在屏幕的底部
    //所以,让我们得到我们与screenBounds.size.height屏幕的高度
    //记住这里被谈论我们GADBannerView的中心,因此,如果我们只是将其设置为
    //我们GADBannerView的高度的一半将通过在屏幕的底部被切除
    //因此,让我们GADBannerView的身高减去一半来解决与adMobView.bounds.size.height / 2
    adMobView.center = CGPointMake(screenBounds.size.width / 2,screenBounds.size.height  - (adMobView.bounds.size.height / 2));

    //将它添加到我们的观点
    [self.view addSubview:adMobView]。
    //我们不必GADBannerView的α设定为0.0,因为这是一种自动透明如果没有广告可
}

// iAd的方法
 - (无效)bannerViewDidLoadAd:(ADBannerView *)旗帜{
    的NSLog(@的iAd获得的广告);
    //我们从iAd的广告收到的所以让表现出来
    //我们将动画的阿尔法从0.0到1.0的过渡
    //也可以让我们的动画从GADBannerView 1.0到0.0将其隐藏
    [UIView的beginAnimations:无背景:NULL];
    iAdView.alpha = 1.0;
    adMobView.alpha = 0.0;
    [UIView的commitAnimations];
}

 - (无效)bannerView:(ADBannerView *)的旗帜didFailToReceiveAdWithError:(NSError *)错误{
    的NSLog(@iAd系统失败);
    //我们没有收到来自广告的iAd因此让我们把它隐藏
    //我们将动画的阿尔法从1.0到0.0的过渡
    //也可以让我们的动画GADBannerView从0.0到1.0,以显示它
    那里是一个广告// AdMob的有近100%的填充率这样的机会几乎肯定
    [UIView的beginAnimations:无背景:NULL];
    iAdView.alpha = 0.0;
    adMobView.alpha = 1.0;
    [UIView的commitAnimations];
}
 

要具备广告在我们需要改变我们分配给我们的广告视图的中心CGPoints在屏幕的顶部。

  //这将需要我们AdBannerView的中心,并将其移动到一个点(X,Y)
//我们希望在设备屏幕的中心AdBannerView.center
//所以让我们让我们的屏幕的宽度和除以2就我们这样做是有screenBounds.size.width / 2
//我们也希望我们的AdBannerView是在屏幕的顶部
//所以,让我们得到我们与screenBounds.origin.y屏幕的原点
//记住这里被谈论我们AdBannerView的中心,因此,如果我们只是将其设置为
//我们AdBannerView的高度的一半将通过在屏幕的顶部被切掉
//所以让我们来添加一半的AdBannerView的高度来解决与iAdView.bounds.size.height / 2
iAdView.center = CGPointMake(screenBounds.size.width / 2,screenBounds.origin.y +(iAdView.bounds.size.height / 2));

//这将需要我们GADBannerView的中心,并将其移动到一个点(X,Y)
//我们希望在设备屏幕的中心GADBannerView.center
//所以让我们让我们的屏幕的宽度和除以2就我们这样做是有screenBounds.size.width / 2
//我们也希望我们的GADBannerView是在屏幕的顶部
//所以,让我们得到我们与screenBounds.origin.y屏幕的原点
//记住这里被谈论我们GADBannerView的中心,因此,如果我们只是将其设置为
//我们GADBannerView的高度的一半将通过在屏幕的顶部被切掉
//所以让我们来添加一半的GADBannerView的高度来解决与adMobView.bounds.size.height / 2
adMobView.center = CGPointMake(screenBounds.size.width / 2,screenBounds.origin.y +(adMobView.bounds.size.height / 2));
 

My iAd/AdMob mediation works fine with all iOS 7 simulators and devices. However, iOS 8 didFailToReceiveAdWithError method doesn't work for any simulators but it works for iOS 8 devices. Problem is I don't have an iPhone 6/6+ device to test. So i'm counting on iOS 8 simulator.

-(void)bannerViewDidLoadAd:(ADBannerView *)banner{
     [UIView beginAnimations:nil context:NULL];
     iAd.frame=CGRectOffset (iAd.frame 0, -667);
     [UIView commitAnimations];

     [UIView beginAnimations:nil context:NULL];
     iAd.frame=CGRectOffset (iAd.frame 0, 0);
     [UIView commitAnimations];
}

-(void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error{
     [UIView beginAnimations:nil context:NULL];
     iAd.frame=CGRectOffset (iAd.frame 0, -740);
     [UIView commitAnimations];

     [UIView beginAnimations:nil context:NULL];
     AdMob.frame=CGRectOffset (iAd.frame 0, -667);
     [UIView commitAnimations];
}

I don't even know if the didFailToReceive coordinates are correct since I have no way to test. I don't understand why didFailToReceiveAdWithError is never called for iOS 8 simulators only? Is this an iOS 8 simulator bug or is there something I can do to fix this issue?

// ignore ^^

 -(AppDelegate *)appdelegate{
  return (AppDelegate *) [[UIApplication sharedApplication] delegate];
  }


  -(void)viewWillAppear:(BOOL)animated{

   //iAD

   _iAdView= [[self appdelegate] iAdView];
   _iAdView.delegate=self;

   screenBounds = [[UIScreen mainScreen] bounds];

   [_iAdView setFrame:CGRectMake(0, 0, _iAdView.bounds.size.width,   _iAdView.bounds.size.height)];

   _iAdView.center = CGPointMake(screenBounds.size.width / 2,   screenBounds.origin.y + (_iAdView.bounds.size.height / 2));

   [self.view addSubview:_iAdView];



   //ADMOB

   _adMobView= [[self appdelegate] adMobView];

  _adMobView = [[GADBannerView alloc] initWithAdSize:kGADAdSizeSmartBannerPortrait];

  _adMobView.adUnitID =  @"My-Unit-ID";

 _adMobView.rootViewController = self;

 GADRequest *request =[GADRequest request];

 request.testDevices = @[ @"Test-Number" ];

 [_adMobView loadRequest:request];

 [_adMobView setFrame:CGRectMake(0, 0, _adMobView.bounds.size.width, _adMobView.bounds.size.height)];

 _adMobView.center = CGPointMake(screenBounds.size.width / 2, screenBounds.size.height - (_adMobView.bounds.size.height / 2)); 

 [self.view addSubview:_adMobView];

 }


 -(void)viewWillDisappear:(BOOL)animated{   //Whether I remove this or not, nothing changes

 //iAD

 _iAdView.delegate = nil;
 _iAdView=nil;

 _iAdView.alpha=0.0; 


  //ADMOB

   _adMobView.delegate=nil;
   _adMobView=nil;

   _adMobView.alpha=0.0;
   }


   -(void)bannerViewDidLoadAd:(ADBannerView *)banner{

    NSLog(@"iAd received");

    _iAdView.alpha=1.0;
    _adMobView.alpha = 0.0;

    [UIView commitAnimations];
    }


    -(void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error{

    NSLog(@"iAd failed, AdMob received");

   _iAdView.alpha=0.0;
   _adMobView.alpha=1.0;

   [UIView commitAnimations];
   }

解决方案

This is everything you need to implement iAd and AdMob banners. It favors iAd and shows an AdMob banner if our app fails to receive an ad from iAd. I've seen alot of questions pertaining to this in the last few weeks so I've literally commented out as much as I can to help everyone understand what is exactly going on here.

// Import iAd and AdMob in your header file
#import "ViewController.h"
// Enter YOUR ad id you receive from AdMob here
#define BANNER_UNIT_ID @"yourAdMobBannerID"

@interface ViewController ()
@end

@implementation ViewController {
    //We will put these here so we can access them globally
    GADBannerView *adMobView;
    ADBannerView *iAdView;
    CGRect screenBounds;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Get device screen size
    // For example, screenBounds on an iPhone 6 will look like this
    // screenBounds.origin.x == 0
    // screenBounds.origin.y == 0
    // screenBounds.size.width == 375
    // screenBounds.size.height == 667
    screenBounds = [[UIScreen mainScreen] bounds];

    // Setup iAd view
    // Create the AdBannerView
    iAdView = [[ADBannerView alloc] initWithFrame:CGRectZero];

    // Set its delegate
    iAdView.delegate=self;

    // This sets the frame origin at (0,0) which would be the top left of the device screen
    // iAdView.bounds.size.width and iAdView.bounds.size.height sets the size of the AdBannerView
    [iAdView setFrame:CGRectMake(0, 0, iAdView.bounds.size.width, iAdView.bounds.size.height)];

    // This will take the center of our AdBannerView and move it to a point (x,y)
    // We want our AdBannerView.center in the center of the device screen
    // So lets get the width of our screen and divide it by 2. We do this with screenBounds.size.width / 2
    // We also want our AdBannerView to be at the bottom of the screen
    // So lets get the height of our screen with screenBounds.size.height
    // Remember were talking about the center of our AdBannerView here so if we just set it to that
    // Half of our AdBannerView's height will be cut off by the bottom of the screen
    // So lets subtract half of our AdBannerView's height to fix that with iAdView.bounds.size.height / 2
    iAdView.center = CGPointMake(screenBounds.size.width / 2, screenBounds.size.height - (iAdView.bounds.size.height / 2));

    // Add it to our view
    [self.view addSubview:iAdView];

    // Our AdBannerView is now at the bottom of our devices screen
    // But it takes a second to receive an ad from iAd's network so lets make it transparent for now
    iAdView.alpha = 0.0;


    // Setup AdMob view
    // Create the GADBannerView
    adMobView = [[GADBannerView alloc] initWithAdSize:kGADAdSizeBanner];

    // Use the BANNER_UNIT_ID we defined earlier
    adMobView.adUnitID = BANNER_UNIT_ID;
    adMobView.rootViewController = self;
    [adMobView loadRequest:[GADRequest request]];

    // This sets the frame origin at (0,0) which would be the top left of the device screen
    // adMobView.bounds.size.width and adMobView.bounds.size.height sets the size of the GADBannerView
    [adMobView setFrame:CGRectMake(0, 0, adMobView.bounds.size.width, adMobView.bounds.size.height)];

    // This will take the center of our GADBannerView and move it to a point (x,y)
    // We want our GADBannerView.center in the center of the device screen
    // So lets get the width of our screen and divide it by 2. We do this with screenBounds.size.width / 2
    // We also want our GADBannerView to be at the bottom of the screen
    // So lets get the height of our screen with screenBounds.size.height
    // Remember were talking about the center of our GADBannerView here so if we just set it to that
    // Half of our GADBannerView's height will be cut off by the bottom of the screen
    // So lets subtract half of our GADBannerView's height to fix that with adMobView.bounds.size.height / 2
    adMobView.center = CGPointMake(screenBounds.size.width / 2, screenBounds.size.height - (adMobView.bounds.size.height / 2));

    // Add it to our view
    [self.view addSubview:adMobView];
    // We don't have to set the alpha of GADBannerView to 0.0 because it is automatically transparent if no ad is available
}

//iAd methods
-(void)bannerViewDidLoadAd:(ADBannerView *)banner {
    NSLog(@"iAd received ad");
    // We received an ad from iAd so lets show it
    // We will animate the transition of its alpha from 0.0 to 1.0
    // Also lets animate our GADBannerView from 1.0 to 0.0 to hide it
    [UIView beginAnimations:nil context:NULL];
    iAdView.alpha = 1.0;
    adMobView.alpha = 0.0;
    [UIView commitAnimations];
}

-(void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error {
    NSLog(@"iAd failed");
    // We failed to receive an ad from iAd so lets hide it
    // We will animate the transition of its alpha from 1.0 to 0.0
    // Also lets animate our GADBannerView from 0.0 to 1.0 to show it
    // AdMob has near a 100% fill rate so the chances of there being an ad are almost certain
    [UIView beginAnimations:nil context:NULL];
    iAdView.alpha = 0.0;
    adMobView.alpha = 1.0;
    [UIView commitAnimations];
}

To have the ads at the top of the screen we need to change the CGPoints we are assigning to our ad view's centers.

// This will take the center of our AdBannerView and move it to a point (x,y)
// We want our AdBannerView.center in the center of the device screen
// So lets get the width of our screen and divide it by 2. We do this with screenBounds.size.width / 2
// We also want our AdBannerView to be at the top of the screen
// So lets get the origin of our screen with screenBounds.origin.y
// Remember were talking about the center of our AdBannerView here so if we just set it to that
// Half of our AdBannerView's height will be cut off by the top of the screen
// So lets add half of our AdBannerView's height to fix that with iAdView.bounds.size.height / 2
iAdView.center = CGPointMake(screenBounds.size.width / 2, screenBounds.origin.y + (iAdView.bounds.size.height / 2));

// This will take the center of our GADBannerView and move it to a point (x,y)
// We want our GADBannerView.center in the center of the device screen
// So lets get the width of our screen and divide it by 2. We do this with screenBounds.size.width / 2
// We also want our GADBannerView to be at the top of the screen
// So lets get the origin of our screen with screenBounds.origin.y
// Remember were talking about the center of our GADBannerView here so if we just set it to that
// Half of our GADBannerView's height will be cut off by the top of the screen
// So lets add half of our GADBannerView's height to fix that with adMobView.bounds.size.height / 2
adMobView.center = CGPointMake(screenBounds.size.width / 2, screenBounds.origin.y + (adMobView.bounds.size.height / 2));