首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >iOS: Tapjoy全屏广告打开多个屏幕

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

Stack Overflow用户
提问于 2013-12-14 10:38:22
回答 1查看 398关注 0票数 3

我试图在我的应用程序中使用Tapjoy,我使用以下代码

代码语言:javascript
复制
-(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];
}

问题是,当我再次回忆起这个方法时,它会同时打开两个屏幕。我越叫这个方法,屏幕就越打开。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-12-23 07:07:39

基本上,问题在于您的notification被观察了多少次,然后您的方法正在执行。因此,防止此问题的一种方法是,一旦发布并观察到notification,然后删除notification observer。另外,这也取决于您的代码,您是如何处理notification部件的。因此,尝试remove observer并检查如下:

代码语言:javascript
复制
-(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];
}
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20582228

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档