3

i'm trying to use Tapjoy for my apps and i'm using the following code

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

the problem is when i recall the method again it opens two screens together .. the more i call this method the more screens open up..

Shaik Riyaz
  • 11,204
  • 7
  • 53
  • 70
Mohamed Emad Hegab
  • 2,665
  • 6
  • 39
  • 64
  • What are you expecting to happen? - You might also want to include the code for methods `getFullScreenAd` and `fullscreenAdClosed` – Wez Dec 17 '13 at 12:12
  • i did implement them this is not the problem.. the problem is that .. whenever i call this method it open multiple ads as many as i call it.. it means when i call it 3 times it gives me 3 fullscreen ads.. what i need is a way to deallocate this – Mohamed Emad Hegab Dec 17 '13 at 14:30
  • So you are saying that the first time you call this you get 1 advert shown, the second time you get 2 adverts shown (so a total of 3 including the first time) and the thrid time you call it you get another 3 so a total of 6 over all method calls? – Wez Dec 17 '13 at 14:58
  • not exactly second time i got 2 ads only third time i got 3 ads .. and so on – Mohamed Emad Hegab Dec 22 '13 at 08:36
  • You need to remove an Observer somewhere in your code. Did you try ?? – Hussain Shabbir Dec 23 '13 at 07:00

1 Answers1

3

Basically the problem is how many times your notification is observed then your method is executing. So one way you can prevent the issue is once notification is posted and observed then remove your notification observer. Also it depends on your code as well, that how you are dealing with notification part. So try to remove observer and check below:-

-(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];
}
Hussain Shabbir
  • 14,801
  • 5
  • 40
  • 56