Gire el iPad y AdMob para no volver a cargar, como iAds

Estoy implementando banners de iAd y AdMob en mi aplicación. En el iPad, tengo algunos problemas extraños cuando el dispositivo gira, específicamente con AdMob.

Con iAds, el banner permanece en la parte inferior de la pantalla cuando el dispositivo gira y no vuelve a cargar el anuncio.

Sin embargo, con AdMob, vuelve a cargar el banner cuando el dispositivo gira, aunque estoy usando el mismo código.

Estoy creando elADBannerView yGADBannerView programáticamente

código de iAd:

self.adBanner.hidden = NO;
self.adBanner = [[self appdelegate] adBanners];
self.adBanner.delegate = self;

if (IDIOM == IPAD)
{
    NSLog(@"***This is the iPad****");
    [self.adBanner setFrame:CGRectMake(0, [[UIScreen mainScreen] bounds].size.height-80, 320, 50)];
    [self.adBanner setTranslatesAutoresizingMaskIntoConstraints:NO];

    [self.view addSubview:self.adBanner];
    NSLayoutConstraint *myConstraint =[NSLayoutConstraint
                                       constraintWithItem:self.adBanner
                                       attribute:NSLayoutAttributeLeading
                                       relatedBy:NSLayoutRelationEqual
                                       toItem:self.view
                                       attribute:NSLayoutAttributeLeading
                                       multiplier:1.0
                                       constant:0];

    [self.view addConstraint:myConstraint];



    myConstraint =[NSLayoutConstraint constraintWithItem:self.adBanner
                                               attribute:NSLayoutAttributeTrailing
                                               relatedBy:NSLayoutRelationEqual
                                                  toItem:self.view
                                               attribute:NSLayoutAttributeTrailing
                                              multiplier:1
                                                constant:0];

    [self.view addConstraint:myConstraint];

    myConstraint =[NSLayoutConstraint constraintWithItem:self.adBanner
                                               attribute:NSLayoutAttributeBottom
                                               relatedBy:NSLayoutRelationEqual
                                                  toItem:self.view
                                               attribute:NSLayoutAttributeBottom
                                              multiplier:1
                                                constant:0];

    [self.view addConstraint:myConstraint];

}

El código de AdMob está debajo. Estoy creando GADBannerView en AppDelegate en applicationDidFinishLaunchingWithOptions:

Actualizar

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // other code
    self.adBanners = [[ADBannerView alloc]init];
    self.adBanners.hidden = YES;

    self.adMobBanners = [[GADBannerView alloc] initWithAdSize:kGADAdSizeSmartBannerPortrait];
    return YES; 
}

En el controlador de vista, cuando estoy creando AdMob, estoy llamando al método para crear AdMob:

Actualizar

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];

    if (![[NSUserDefaults standardUserDefaults] boolForKey:@"IAPSuccessful"])
    {
        NSLog(@"View will appear and the IAP is not Successful");
        [self sharedBanners];
    }
    else
    {
        NSLog(@"View will appear and the IAP IS Successful");
        self.adBanner.hidden = YES;
        self.adMobBannerView.hidden = YES;
    }  
}
- (void)sharedBanners
{
    self.adMobBannerView = [[self appdelegate] adMobBanners];
    self.adMobBannerView.rootViewController = self;
    self.adMobBannerView.delegate = self;
    self.adBanner = [[self appdelegate] adBanners];
    self.adBanner.delegate = self;

}

- (void)bannerViewDidLoadAd:(ADBannerView *)banner
{
        [self displayiAdsOrNot];    
}

- (void)adViewDidReceiveAd:(GADBannerView *)view
{
        [self displayAdMobBannerOrNot];

}

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

- (void)displayAdMobBannerOrNot
{

    self.adBanner.hidden = YES;
    self.adMobBannerView.hidden = NO;
    self.adMobBannerView = [[self appdelegate] adMobBanners];
    self.adMobBannerView.rootViewController = self;
    self.adMobBannerView.delegate = self;

       if (IDIOM == IPAD) {
        [self.adMobBannerView setFrame:CGRectMake(0, [[UIScreen mainScreen] bounds].size.height-80, 320, 50)];
                    self.adMobBannerView.adUnitID = @"MYUNIT";

        //   [self.adMobBannerView setFrame:CGRectMake(0, [[UIScreen mainScreen] bounds].size.height-80, CGSizeFromGADAdSize(kGADAdSizeFullBanner).width, 50)];

        GADRequest *request = [GADRequest request];
        [self.adMobBannerView loadRequest:request];

        [self.adMobBannerView setTranslatesAutoresizingMaskIntoConstraints:NO];
        [self.view addSubview:self.adMobBannerView];

        NSLayoutConstraint *myConstraint =[NSLayoutConstraint
                                           constraintWithItem:self.adMobBannerView
                                           attribute:NSLayoutAttributeLeading
                                           relatedBy:NSLayoutRelationEqual
                                           toItem:self.view
                                           attribute:NSLayoutAttributeLeading
                                           multiplier:1.0
                                           constant:0];

        [self.view addConstraint:myConstraint];

        myConstraint =[NSLayoutConstraint constraintWithItem:self.adMobBannerView
                                                   attribute:NSLayoutAttributeTrailing
                                                   relatedBy:NSLayoutRelationEqual
                                                      toItem:self.view
                                                   attribute:NSLayoutAttributeTrailing
                                                  multiplier:1
                                                    constant:0];

        [self.view addConstraint:myConstraint];

        myConstraint =[NSLayoutConstraint constraintWithItem:self.adMobBannerView
                                                   attribute:NSLayoutAtt,ributeBottom
                                                   relatedBy:NSLayoutRelationEqual
                                                      toItem:self.view
                                                   attribute:NSLayoutAttributeBottom
                                                  multiplier:1
                                                    constant:0];

        [self.view addConstraint:myConstraint];
    }
}

** Tenga en cuenta que este no es el orden de los métodos. El orden real es AppDelegate, sharedBanner, displayAdMob, viewWillAppear y luego los métodos de delegado. ** **

La razón de las restricciones es que quiero tener elADBannerView yGADBannerView anclado en la parte inferior de la pantalla y al final y a la izquierda. Con esto quiero decir, lo quiero en la parte inferior de la pantalla, comenzando en el borde izquierdo, terminando en el borde derecho y en la parte inferior.

Problema

Cuando se carga el banner de iAd, funciona en toda la parte inferior de la pantalla del iPad, comenzando a la izquierda y terminando a la derecha. Si giro el dispositivo, el banner de iAd no se vuelve a cargar y continúa girando junto con el iPad. Sin embargo, el banner de AdMob se muestra en modo vertical, pero cuando lo giro, desaparece y luego se vuelve a cargar.

He intentado usarPersonalización de anuncios de banner para las constantes en lugar de tamaños explícitos para el banner de AdMob. Por ejemplo:

        if (UIInterfaceOrientationLandscapeLeft)
        {
            NSLog(@"Left");
            [self.adMobBannerView setFrame:CGRectMake(0, [[UIScreen mainScreen] bounds].size.height-80, CGSizeFromGADAdSize(kGADAdSizeSmartBannerLandscape).width, 90)];
        }
        else if (UIInterfaceOrientationLandscapeRight)
        {
            NSLog(@"Right");
            [self.adMobBannerView setFrame:CGRectMake(0, [[UIScreen mainScreen] bounds].size.height-80, CGSizeFromGADAdSize(kGADAdSizeSmartBannerLandscape).width, 90)];
        }
        else if (UIInterfaceOrientationPortrait)
        {
            NSLog(@"Portraait");
            [self.adMobBannerView setFrame:CGRectMake(0, [[UIScreen mainScreen] bounds].size.height-80, CGSizeFromGADAdSize(kGADAdSizeSmartBannerPortrait).width, 90)];
        }

Pero el problema aún está presente.

Respuestas a la pregunta(1)

Su respuesta a la pregunta