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

标签 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];
}

问题是当我再次记忆起这个方法时,它同时打开了两个屏幕.. 我越多调用此方法,打开的屏幕就越多..

最佳答案

基本上,问题是您的notification 被观察到多少次,然后您的方法正在执行。因此,您可以防止此问题的一种方法是,一旦发布并观察到 ​​notification,然后删除您的 notification observer。这也取决于您的代码,即您如何处理 notification 部分。所以尝试删除观察者并检查以下内容:-

-(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];
}

关于iOS:Tapjoy 全屏广告打开多个屏幕,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20582228/

相关文章:

ios - 当另一个 viewController 隐藏状态栏时,UINavigationBar 在状态栏下方移动

iphone - UItable 标题在滚动时始终显示

ios - 在 Jest 每个测试用例中获取警告和 console.error

c++ - 在 Objective-C/C++ 中使用 Signals2 将 C++ 模型连接到 Controller

android - Fragment 中的 TapJoy 优惠列表

ios - Tapjoy 展示位置问题 广告在应用程序中不可见

android - 无法从 Tapjoy 积分墙获得点数?

iphone - 在iPhone中创建QR码

objective-c - 在 View Controller 子类上添加导航 Controller

ios - 如何在 iOS 的 Realm 中使用主键( objective-c )