简体   繁体   English

iPhone应用程序崩溃与admob?

[英]iPhone app crashes with admob?

I am having an iphone app with admob on two screens's viewdidLoad 我在两个屏幕的viewdidLoad上有一个带有admob的iphone应用程序

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 * - [GADOpener didOpen]:消息发送到解除分配的实例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. message sent to deallocated instance问题的message sent to deallocated instance是由于您尝试使用在此错误弹出之前已从代码中的某个位置删除的变量。 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: 您需要确保正在创建此对象的视图控制器正确retain它,以便在您需要再次使用它之前不会取消分配它:

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. 听起来你可能需要刷新你的内存管理文档 ,但它的要点是,无论你在哪里调用alloc ,你都在管理那个内存,需要在完成后调用release 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) . 如果你需要一个变量来保持比autorelease d对象更长的时间,那么你需要创建一个实例变量并使用ivar属性@property (nonatomic, retain)自己retain对象。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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