3

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

问题是当我再次回忆该方法时,它会同时打开两个屏幕..我调用此方法的次数越多,打开的屏幕就越多..

4

1 回答 1

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];
}
于 2013-12-23T07:07:39.957 回答