简体   繁体   中英

iPhone app crashes with admob?

I am having an iphone app with admob on two screens's viewdidLoad

My code is:

AbMob =[[GADBannerView alloc]initWithFrame:CGRectMake(0.0,self.view.frame.size.height-195, 320, 50)];

    AbMob.adUnitID = AdMob_ID;
    AbMob.rootViewController = self;
    [self.view addSubview:AbMob];



    GADRequest *r = [[GADRequest alloc] init];
    r.testing = NO;

    [AbMob loadRequest:r];

Problem is this code works fine on one screen but crashes on other screen with error

* -[GADOpener didOpen]: message sent to deallocated instance 0x6074750

Can anybody tell me what could be the problem

You have a retain/release problem somewhere in your code. You say it works in one view, but not another - this makes me believe that you are storing this instance outside of your view controllers. The message sent to deallocated instance issue is due to you trying to use a variable that has been removed from memory somewhere in the code before this error pops up. You need to ensure that the view controller that is creating this object is properly retain ing it so that it does not get deallocated before you need to use it again with:

GADBannerView *_adMobBannerView;

@property(nonatomic,retain) GADBannerView *adMobBannerView; //view controller retains object when using self.adMobBannerView = bla

It sounds like you may need to brush up on your memory management documentation , but the gist of it is that anywhere you are calling alloc , you are managing that memory and need to call release when you are done with it. If you need a variable to stick around for longer than an autorelease d object is living for, then you need to create an instance variable and retain the object yourself with ivar properties @property (nonatomic, retain) .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM