0

当我启动我的应用程序时,构建成功,但几乎一开始它就崩溃并突出显示以下内容:

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 文件,我使用的代码来自 google 在横幅上的演示应用程序:

@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]);
}
4

1 回答 1

-1

这是你的问题:

[GADObjectPrivate changeState:]: unrecognized selector sent to instance

您是否正确输入了方法名称?这意味着您调用的方法不存在。更具体地说,GADObjectPrivate 类不包含此方法。

调用 changeState: 时的崩溃:之前已询问过。看到这个问题:

AdMob 因 [GADObjectPrivate changeState:] 崩溃:无法识别的选择器

于 2013-08-06T20:46:47.367 回答