我想在我的ios应用程序中添加admob。
我已经遵循了该教程:
https://developers.google.com/mobile-ads-sdk/docs/admob/fundamentals?hl=en#ios
但即使使用示例项目或使用该代码在我的ios项目中添加源代码,我也有一个错误:
* 由于未捕获的异常'NSInvalidArgumentException'而终止应用程序,原因:' - [GADBannerView private]:无法识别的选择器发送到实例0x1727d0'
使用该源代码:
ViewController.h
#import <UIKit/UIKit.h>
#import "GADBannerView.h"
@interface ViewController : UIViewController{
GADBannerView *bannerView_;
}
@end
和
ViewController.m
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Create a view of the standard size at the bottom of the screen.
bannerView_ = [[GADBannerView alloc]
initWithFrame:CGRectMake(0.0,
self.view.frame.size.height -
GAD_SIZE_320x50.height,
GAD_SIZE_320x50.width,
GAD_SIZE_320x50.height)];
// Specify the ad's "unit identifier." This is your AdMob Publisher ID.
bannerView_.adUnitID = @"MYID";
// Let the runtime know which UIViewController to restore after taking
// the user wherever the ad goes and add it to the view hierarchy.
bannerView_.rootViewController = self;
[self.view addSubview:bannerView_];
// Initiate a generic request to load it with an ad.
[bannerView_ loadRequest:[GADRequest request]];
}
- (void)viewDidUnload
{
[super viewDidUnload];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
} else {
return YES;
}
}
@end
答案 0 :(得分:1)
我遇到了类似的问题。我使用-all_load
链接器标志修复了它。
这就是你需要的。
https://developers.google.com/mobile-ads-sdk/docs/#incorporating
答案 1 :(得分:1)
如果您已添加-all_load
,但仍然无效:
祝你好运:)