iOS:Tapjoy全屏广告打开多个屏幕

时间:2013-12-14 10:38:23

标签: ios objective-c tapjoy

我正在尝试使用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];
}

问题是当我再次回想起这个方法时,它会一起打开两个屏幕.. 我称之为这种方法越多,屏幕就会越多......

1 个答案:

答案 0 :(得分:3)

基本上问题是你的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]; } 并查看以下内容: -

{{1}}