我试图在我的应用程序中使用Tapjoy,我使用以下代码
-(void)getTapJoyAd{
[Tapjoy getFullScreenAd];
// A notification method must be set to retrieve the fullscreen ad object.
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(getFullScreenAd:)
name:TJC_FULL_SCREEN_AD_RESPONSE_NOTIFICATION
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(fullscreenAdClosed:)
name:TJC_VIEW_CLOSED_NOTIFICATION
object:nil];
// This method requests the tapjoy server for current virtual currency of the user.
[Tapjoy getTapPoints];
// A notification method must be set to retrieve the points.
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(getUpdatedPoints:) name:TJC_TAP_POINTS_RESPONSE_NOTIFICATION object:nil];
}问题是,当我再次回忆起这个方法时,它会同时打开两个屏幕。我越叫这个方法,屏幕就越打开。
发布于 2013-12-23 07:07:39
基本上,问题在于您的notification被观察了多少次,然后您的方法正在执行。因此,防止此问题的一种方法是,一旦发布并观察到notification,然后删除notification observer。另外,这也取决于您的代码,您是如何处理notification部件的。因此,尝试remove observer并检查如下:
-(void)viewDidDisappear:(BOOL)animated
{
[[NSNotificationCenter defaultCenter]removeObserver:self name:TJC_FULL_SCREEN_AD_RESPONSE_NOTIFICATION object:nil];
[[NSNotificationCenter defaultCenter]removeObserver:self name:TJC_VIEW_CLOSED_NOTIFICATION object:nil];
[[NSNotificationCenter defaultCenter]removeObserver:self name:TJC_TAP_POINTS_RESPONSE_NOTIFICATION object:nil];
}https://stackoverflow.com/questions/20582228
复制相似问题