0

When I launch my app the build succeeds, but when almost right in the beginning it crashes and highlights the following:

return UIApplicationMain(argc, argv, nil, NSStringFromClass([yes_or_no_AppDelegate class]));

and says:

Thread 1: signal SIGABRT




int main(int argc, char *argv[])
{
    @autoreleasepool {
        return UIApplicationMain(argc, argv, nil, NSStringFromClass([yes_or_no_AppDelegate class]));
    }
}

Error message in console:

[GADObjectPrivate changeState:]: unrecognized selector sent to instance

I found out that this is the part that is causing the error. If I delete it I'm able to launch the app.

[self.bannerView setRootViewController:self];

But when i launch the app i don't receive a banner and receive error message in console:

Must set the rootViewController property of GADBannerView before calling loadRequest:

This is my .h file and the code I've used is from googles demo app on banners:

@class GADBannerView, GADRequest;

@interface MainViewController : UIViewController <GADBannerViewDelegate>  {


    GADBannerView *adBanner_;
}

@property(nonatomic, strong) GADBannerView *adBanner;

and my .m file also from google demo app:

@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]);
}
Tarek Hallak
  • 18,422
  • 7
  • 59
  • 68

1 Answers1

-1

Here's your problem:

[GADObjectPrivate changeState:]: unrecognized selector sent to instance

Did you type the method name correctly? This means the method you are calling does not exist. More specifically the GADObjectPrivate class does not contain this method.

The crash when calling changeState: has been asked before. See this question:

AdMob crashes with [GADObjectPrivate changeState:]: unrecognized selector

Community
  • 1
  • 1
dana0550
  • 1,125
  • 1
  • 9
  • 16
  • "I found out that this is the part that is causing the error" was stated right below "[GADObjectPrivate changeState:]: unrecognized selector sent to instance" – heinst Aug 06 '13 at 20:50
  • Then if that is the case right above it he states "Error message in console:" – heinst Aug 06 '13 at 20:53
  • the link worked for me when I created a new project, but when I changed it in my current project I recieved 12 errors, any idea? – user2654446 Aug 06 '13 at 21:23