当我启动我的应用程序时,构建成功,但是在开始时几乎正确,它会崩溃并突出显示以下内容:
return UIApplicationMain(argc, argv, nil, NSStringFromClass([yes_or_no_AppDelegate class]));
并说:
Thread 1: signal SIGABRT
int main(int argc, char *argv[])
{
@autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([yes_or_no_AppDelegate class]));
}
}
控制台中的错误消息:
[GADObjectPrivate changeState:]: unrecognized selector sent to instance
我发现这是造成错误的部分。如果我删除它,我就可以启动该应用程序。
[self.bannerView setRootViewController:self];
但是当我启动应用程序时,我没有收到横幅并在控制台中收到错误消息:
Must set the rootViewController property of GADBannerView before calling loadRequest:
这是我的.h文件,我使用的代码来自横幅上的googles demo app:
@class GADBannerView, GADRequest;
@interface MainViewController : UIViewController <GADBannerViewDelegate> {
GADBannerView *adBanner_;
}
@property(nonatomic, strong) GADBannerView *adBanner;
和我的.m文件也来自谷歌演示应用程序:
@synthesize adBanner = adBanner_;
#pragma mark init/dealloc
// Implement viewDidLoad to do additional setup after loading the view,
// typically from a nib.
- (void)viewDidLoad {
[super viewDidLoad];
// Initialize the banner at the bottom of the screen.
CGPoint origin = CGPointMake(0.0,
self.view.frame.size.height -
CGSizeFromGADAdSize(kGADAdSizeBanner).height);
// Use predefined GADAdSize constants to define the GADBannerView.
self.adBanner = [[GADBannerView alloc] initWithAdSize:kGADAdSizeBanner
origin:origin]
;
// Note: Edit SampleConstants.h to provide a definition for kSampleAdUnitID
// before compiling.
self.adBanner.adUnitID = kSampleAdUnitID;
self.adBanner.delegate = self;
[self.bannerView setRootViewController:self];
[self.view addSubview:self.adBanner];
self.adBanner.center =
CGPointMake(self.view.center.x, self.adBanner.center.y);
[self.adBanner loadRequest:[self createRequest]];
}
- (void)dealloc {
adBanner_.delegate = nil;
}
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskPortrait;
}
#pragma mark GADRequest generation
// Here we're creating a simple GADRequest and whitelisting the application
// for test ads. You should request test ads during development to avoid
// generating invalid impressions and clicks.
- (GADRequest *)createRequest {
GADRequest *request = [GADRequest request];
// Make the request for a test ad. Put in an identifier for the simulator as
// well as any devices you want to receive test ads.
request.testDevices =
[NSArray arrayWithObjects:
// TODO: Add your device/simulator test identifiers here. They are
// printed to the console when the app is launched.
nil];
return request;
}
#pragma mark GADBannerViewDelegate impl
// We've received an ad successfully.
- (void)adViewDidReceiveAd:(GADBannerView *)adView {
NSLog(@"Received ad successfully");
}
- (void)adView:(GADBannerView *)view
didFailToReceiveAdWithError:(GADRequestError *)error {
NSLog(@"Failed to receive ad with error: %@", [error localizedFailureReason]);
}
答案 0 :(得分:-1)
这是你的问题:
[GADObjectPrivate changeState:]: unrecognized selector sent to instance
您是否正确输入了方法名称?这意味着您调用的方法不存在。更具体地说,GADObjectPrivate类不包含此方法。
之前已经询问过调用changeState时的崩溃。看到这个问题:
AdMob crashes with [GADObjectPrivate changeState:]: unrecognized selector