1

在 ViewController.h 我的代码是

#import <UIKit/UIKit.h>
@class GADBannerView;
@interface ViewController : UIViewController
@property (strong, nonatomic) IBOutlet GADBannerView *addView;
@end

我的代码是 ViewController.m 文件

@import GoogleMobileAds;
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    self.addView.adUnitID = @"ca-app-pub-9210017787755331/6998637808";
    self.addView.rootViewController = self;
    GADRequest *request = [GADRequest request];
        request.testDevices = @[
                            @"2077ef9a63d2b398840261c8221a0c9a"  // Eric's iPod Touch
                            ];
    [self.addView loadRequest:request];
}

最后我禁用了位码。并在 plist 文件中添加了 ATS(应用程序传输层安全设置)任何人请告诉我发生了什么问题以及我该如何克服这个问题。错误日志在这里

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIView setAdUnitID:]: unrecognized selector sent to instance 0x7f88bb51e090'
4

2 回答 2

1

确保您的 bannerView 已在情节提要中分配了 GADBannerView 类。

您可以在故事板中选择您的横幅视图,然后转到自定义类部分并在类选项中分配 GADBannerView。

这对我有用。

于 2016-03-23T01:43:52.380 回答
0

您的代码似乎没问题,但如果您收到此错误,则意味着您的addView变量没有adUnitId属性,这意味着它的行为不像GADBannerView.

在 Google 的示例中,一切都发生在 .m 文件中。在您的代码中,一些 AdMob 在 .h 文件中导入,一些在 .m 文件中。该问题可能与将标头导入错误的位置有关。尝试像谷歌那样做。

于 2015-12-28T17:13:38.013 回答