简体   繁体   中英

Adding AdMob Interstitial ads in addition to banner ads (IOS)

I have banner ads successfully working in my iOS application, but am struggling adding the code for interstitial ads as I cannot get rid of the error :- "No visible @interface for 'GADInterstitial' declares the selector 'initWithAdUnitId:'".

I am a novice developer and am sure it's a simple mistake I'm making. Can anyone help please ?

My viewcontroller.h looks like this :-

#import <UIKit/UIKit.h>
#import "GADBannerView.h"
#import "GADRequest.h"
@import GoogleMobileAds;

@class GADBannerView, GADRequest;
@class GADInterstitial, GADRequest;

@interface GenTeamViewController : UIViewController
    <GADBannerViewDelegate, GADInterstitialDelegate> {
    GADBannerView *bannerView_;
    GADInterstitial *interstitialView_;
    NSString *teamName;
    UILabel *teamLabel;
    }


@property(nonatomic, strong) GADInterstitial *interstitial;

@property (nonatomic, strong)GADBannerView *bannerView;
-(GADRequest *)createRequest;
,
,
,
@end

The view controller .m looks like :-

- (void)viewDidLoad
{
    [super viewDidLoad];

    self.interstitial = [[GADInterstitial alloc] initWithAdUnitID:@"xxxxxxxxx"];
    GADRequest *request = [GADRequest request];
// Requests test ads on test devices.
    request.testDevices = @[@"xxxxxxxxx"];
    [self.interstitial loadRequest:request];

Make sure your AdMob SDK version is 7.2.1 or newer. The release notes for 7.2.1 state:

Added GADInterstitial initWithAdUnitID: and deprecated GADInterstitial init .

So initWithAdUnitID: will not work with AdMob SDK versions older than 7.2.1.

Also, remove #import "GADBannerView.h" and #import "GADRequest.h" from your header file. You're already importing the entire framework with @import GoogleMobileAds; .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM