1

I have successfully removed ads from the app with an in app purchase.

The problem is that if I close the app and reopen. The ads start up again.

I have 2 main scenes. The GameOverScene and the GameScene. The In App Purchase happens in the GameOverScene.

GameOverScene.m :

- (void)OnRemoveADS {
    [self showPurchaseAlert: IAP_Q_RemoveADS  :0];

    g_bRemoveADS = [[NSUserDefaults standardUserDefaults] boolForKey: @"REMOVEADS"];

    // For HZInterstitialAd, HZVideoAd, and HZIncentivizedAd, just check the BOOL to see if an ad should be shown
    if (!g_bRemoveADS) {
        [HZInterstitialAd show];

        [self removeBannerAds];
        [self disableAds];
        NSLog(@"Disable ads is called");
    }
}

- (void)removeBannerAds {
    HZBannerAdOptions *options = [[HZBannerAdOptions alloc] init];

    [HZBannerAd placeBannerInView:self.view
                         position:HZBannerPositionBottom
                          options:options
                          success:^(HZBannerAd *banner) {
                              if (g_bRemoveADS) { // case (2)
                                  // Just discard the banner
                                  [banner setHidden: YES];
                                  [banner removeFromSuperview];
                                  banner = nil;

                                  //_currentBannerAd = banner;

                                  NSLog(@"Banner ad removed!GameOverScene");
                              } else {
                                  // Keep a reference to the current banner ad, so we can remove it from screen later if we want to disable ads.
                                  _currentBannerAd = banner;
                              }
                              NSLog(@"Ad Shown! GameOverScene");
                          } 
                          failure:^(NSError *error) {
                              NSLog(@"Error = %@",error);
                          }];
}

- (void)disableAds {
    [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"REMOVEADS"];
    [_currentBannerAd removeFromSuperview]; // case (3)
}

GameScene.m :

-(id) init {
    if (self = [super init]) {
        if (!g_bRemoveADS) {
            g_bRemoveADS=FALSE;
            [[NSUserDefaults standardUserDefaults] setBool:g_bRemoveADS forKey:@"REMOVEADS"];
            [[NSUserDefaults standardUserDefaults] synchronize];
        } else {
            g_bRemoveADS=TRUE;
            [[NSUserDefaults standardUserDefaults] setBool:g_bRemoveADS forKey:@"REMOVEADS"];
            [[NSUserDefaults standardUserDefaults] synchronize];
        }
    }
}

The way I'm trying to solve it is by using the same code from the GameOverScene.m in the AppDelegate.m that way when the app starts up it will remove the ads.

AppDelegate.m :

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    g_bRemoveADS = [[NSUserDefaults standardUserDefaults] boolForKey: @"REMOVEADS"];

    if (!g_bRemoveADS) {

        [HZInterstitialAd show];

        [self disableAds];
        NSLog(@"Disable ads is called");
    }
}
4

2 に答える 2