-1

I did the following:

1) Added iAd.framework into iOS project. i imported iAd/iAd.h and .m into project.

2) I opened AdMob account. In mediation i made iAd cpm higher than AdMob cpm.

3) Downloaded the AdMob SDK iOS 7.0 SDK into project and it comes with AdMob adapter. Imported GoogleMobileAds into .h and .m files in project

4) Downloaded the iAd adapter into project.

5) Under Build Settings in Other linker flags I added -ObjC so it's in debug and release.

It states in Admob Mediation instructions "There is no need to write additional code to create ad views from each ad network. The AdMob mediation SDK will invoke each ad network's adapters and SDK as necessary to create ads"

Not adding any code, doesn't work.

I have 1 ViewController for ads to share. 3 methods in that 1 VC. 1st= viewDidLoad method, 2nd= StartGame method, and 3rd= GameOver method. Then back to viewDidLoad after GameOver.

So Then I added iad code in viewDidLoad and made iad hide in didFailToReceiveAdWithError and AdMob show.

This made iAd load and iAd stays showing test banner for like 5 minutes before it fails and AdMob loads. However, AdMob instantly changes back to iAd after I leave the GameOver page and go back to viewDidLoad.

So I don't think mediation is working properly because the ad banners aren't supposed to be affected by any of the methods. What did I do wrong? How do I set up mediation properly?

My code:

-(void)viewDidLoad{
self.iAD = [[ADBannerView alloc] initWithFrame:CGRectMake(0, 60, 375, 50)];
[self.iAD setDelegate:self];
[self.view addSubview:self.iAD];   
}

-(void)bannerViewDidLoadAd:(ADBannerView *)banner{
  self.iAD.hidden=NO;
}

 -(void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error{
  [self.iAD setAlpha:0];
  self.iAD.hidden=YES;

  self.bannerView = [[GADBannerView alloc] initWithAdSize:kGADAdSizeSmartBannerPortrait]; 
  self.AdMob.adUnitID = @"my-unit-id";
  self.AdMob.rootViewController = self;
  self.AdMob.delegate = self;
  [self.view addSubview:self.AdMob];
  GADRequest *request =[GADRequest request];
  request.testDevices = @[ @"278b11d6d1cb3f7d10414d6b2686d0e5 ];  
  [self.bannerView loadRequest:request];
   }
Jet
  • 555
  • 1
  • 7
  • 19
  • Do you have any code you could provide to narrow your question down? It is very broad as of right now and there is no clear problem, just a big one at the moment. Also, starting in AdMob 7.0 you are not required to add -ObjC to Other Linker Flags.. – Daniel Storm Feb 16 '15 at 16:12

2 Answers2

0

I'm not familiar with AdMob's iAd adapter but it sounds like what it is meant for is showing one AdMob view and having AdMob mediate on their end whether to show an iAd ad or an AdMob ad based on the CPM they can acquire at that point. Your code shows that you want to implement iAd and AdMob separately and show one or the other based on whether they receive an ad or not. Also, you should not be creating new iAd and AdMob banner views each time you want to show an ad. You should create one of each initially and show them at the appropriate times in your application. The reason your iAd ad shows immediately after leaving your gameOver view is because viewDidLoad is called where you create a brand new iAd view again. To accomplish what you are trying to do in code you should create a function to create the ad views initially or use a conditional statement in your viewDidLoad to make sure the ad views are only created once. My example does this with a conditional statement and then moves the iAd/AdMob ad view on or off the screen if iAd has received an ad or not.

//ViewController.h
#import <iAd/iAd.h>
#import <GoogleMobileAds/GoogleMobileAds.h>

@interface ViewController : UIViewController <ADBannerViewDelegate>

@end


//ViewController.m
#define BANNER_UNIT_ID @"your admob banner id"

@implementation ViewController {
        //Ads
        GADBannerView *adMobView;
        ADBannerView *iAdView;
        CGRect screenBounds;
        BOOL bannerIsVisible;
        BOOL haveCreatedAdViews;
    }

- (void)viewDidLoad {
    [super viewDidLoad];
    if (!haveCreatedAdViews) {
        // Get device screen size
        screenBounds = [[UIScreen mainScreen] bounds];

        // Setup iAd view
        iAdView = [[ADBannerView alloc] initWithFrame:CGRectZero];
        [self.view addSubview:iAdView];
        iAdView.delegate=self;
        [iAdView setFrame:CGRectMake(0,
                                       0,
                                       iAdView.bounds.size.width,
                                       iAdView.bounds.size.height)];
        iAdView.center = CGPointMake(screenBounds.size.width / 2, screenBounds.size.height + (iAdView.bounds.size.height / 2));

        // Setup AdMob view
        adMobView = [[GADBannerView alloc] initWithAdSize:kGADAdSizeBanner];
        adMobView.adUnitID = BANNER_UNIT_ID;
        adMobView.rootViewController = self;
        [self.view addSubview:adMobView];
        [adMobView loadRequest:[GADRequest 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));
        // Start AdMobView on screen
        adMobView.frame = CGRectOffset(adMobView.frame, 0, -50);
        //iAd banner is not visible
        bannerIsVisible = NO;
        haveCreatedAdViews = YES;
    }
}

//iAd
-(void)bannerViewDidLoadAd:(ADBannerView *)banner {
    NSLog(@"iAd received ad");
    if (!bannerIsVisible) {
        // Move iAd on screen
        [UIView beginAnimations:nil context:NULL];
        iAdView.frame = CGRectOffset(iAdView.frame, 0, -50);
        [UIView commitAnimations];
        bannerIsVisible = YES;

        // Move AdMob off screen
        [UIView beginAnimations:nil context:NULL];
        adMobView.frame = CGRectOffset(adMobView.frame, 0, 50);
        [UIView commitAnimations];
    }
}

-(void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error {
    NSLog(@"iAd failed");
    if (bannerIsVisible) {
        // Move iAd off screen
        [UIView beginAnimations:nil context:NULL];
        iAdView.frame = CGRectOffset(iAdView.frame, 0, 50);
        [UIView commitAnimations];
        bannerIsVisible = NO;

        // Move AdMob on screen
        [UIView beginAnimations:nil context:NULL];
        adMobView.frame = CGRectOffset(adMobView.frame, 0, -50);
        [UIView commitAnimations];
    }
}
Daniel Storm
  • 18,301
  • 9
  • 84
  • 152
  • I'm trying your code from above I put the Ads on top instead of on bottom however there is a weird animation of when the view loads and iAd banner appears, the animation is like iAd banner swiftly scrolls from bottom of screen to top of screen. How do I stop that from happening? – Jet Feb 21 '15 at 01:00
  • I just practiced with your code for a few days and i've noticed it's incorrect. It loads both ads at the same time. What's the point of hiding an ad that's currently showing? The iAd is showing and AdMob is showing. BannerViewDidLoadAd you have iAd showing Ad and Admob showing Ad but the AdMob is showing ad off screen. Then out of nowhere in didFailToReceiveAdWithError they mediate and AdMob is now showing add on screen while iAd is offscreen showing an ad. What's the point of that? – Jet Feb 24 '15 at 23:54
  • I think you're confused. If `didFailToReceiveAdWithError` is called then there is no ad for the iAdView to display. The purpose of this code is to first try to get an iAd ad. If an ad is not available then an AdMob ad is displayed. As far as you trying to display the ads on the top of the screen you need to change the CGPoints of the ad views. I've completely commented out every possible detail of this here (http://stackoverflow.com/a/28708377/2108547). If you come across something you do not understand please reference the Apple Docs (https://developer.apple.com/library/ios/navigation/) – Daniel Storm Feb 25 '15 at 00:01
-1

I had a similar problem. I use this in my didFailToReceiveAdWithError:

[self.bannerView removeFromSuperview];

and after that I initialise my adMobView ...

Panayot
  • 484
  • 1
  • 6
  • 18