在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];
}最后,我禁用了Bitcode。并在plist文件中添加了ATS(应用程序传输层安全设置)。请告诉我发生了什么问题,以及如何克服这个问题。错误日志在此处
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIView setAdUnitID:]: unrecognized selector sent to instance 0x7f88bb51e090'发布于 2016-03-23 09:43:52
确保您的bannerView已在情节提要中分配了GADBannerView类。
您可以在故事板中选择您的横幅视图,然后转到自定义类部分并在类选项中指定GADBannerView。
这对我很有效。
发布于 2015-12-29 01:13:38
你的代码看起来没问题,但是如果你得到这个错误,那就意味着你的addView变量没有adUnitId属性,这意味着它的行为不像GADBannerView。
在谷歌的example中,一切都发生在.m文件中。在代码中,一些AdMob导入到.h文件中,另一些导入到.m文件中。这个问题可能与在错误的位置导入头部有关。试着像谷歌一样去做。
https://stackoverflow.com/questions/34497532
复制相似问题