【问题标题】:IOS Admob Interstitial for objective-cIOS Admob Interstitial for Objective-c
【发布时间】:2016-06-05 12:28:40
【问题描述】:

我在 viewDidLoad 上实施了插页式广告,但我需要这方面的帮助。 我希望 Interstitial 每次 viewDidLoad 出现时都不显示,例如我希望它显示一次是的,一次不显示。与案例有关。

  • 案例一展示
  • 案例 2 不显示
  • 案例3展示
  • ……

这是我的代码:

 - (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.

    self.interstitial = [[GADInterstitial alloc] initWithAdUnitID:@"a151b7d316a5c1d"];
    self.interstitial.delegate = self;
    [self.interstitial loadRequest: [GADRequest request]];
}
- (void)interstitialDidReceiveAd:(GADInterstitial *)interstitial {
    [interstitial presentFromRootViewController:self];
}

【问题讨论】:

    标签: ios objective-c admob interstitial


    【解决方案1】:

    我对我的广告采取同样的一次性、一次性的方式。我只是使用用户默认值来保存计数器。也许尝试以下。下面的代码写得很清楚,所以有点长,但是一旦你知道它在做什么,你就可以进去收紧它(例如,使用adCount += 1;而不是adCount = adCount + 1;等。希望这会有所帮助!

    - (void)viewDidLoad
    {
        [super viewDidLoad];
    
        //Call to your helper method
        //Stop viewDidLoad here if the method returns NO
    
        if (![self _shouldShowInterstitial]) return;
    
        self.interstitial = [[GADInterstitial alloc];
        initWithAdUnitID:@"a151b7d316a5c1d"];
        self.interstitial.delegate = self;
        [self.interstitial loadRequest: [GADRequest request]];
    }
    
    - (BOOL)_shouldShowInterstitial
    {
        //1. Recover user default holding a counter
        BOOL retVal = NO;
        NSString *adKey = @"shouldShowInterstitialOnLoadDefaultKey";
        NSInteger adCount = [[NSUserDefaults standardUserDefaults]integerForKey:adKey];
    
        //2. If the counter is 1, return YES for showing an ad and reset the count to 0
        if (adCount > 0) {
            retVal = YES;
            adCount = 0;
    
        //3. If the count is 0, no ad is required, but increment it so next time the ad will show
        } else {
            retVal = NO;
            adCount = adCount + 1;
        }
    
        //4. Save your defaults
        [[NSUserDefaults standardUserDefaults] setInteger:adCount forKey:adKey];
        [[NSUserDefaults standardUserDefaults] synchronize];
    
        //5. Return your bool value
        return retVal;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多