2016-06-05 4 views
0

viewDidLoad에 삽입 광고를 구현했지만 도움이 필요합니다. viewDidLoad가 표시 될 때마다 삽입 광고가 표시되지 않도록하고 싶습니다 (예 : 한 번 표시하려면 예, 한 번만 표시).IOS Admob 대칭 삽입 광고

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

답변

1
:

  • 사례 1
  • 사례 3은 쇼
  • 표시되지 않습니다 쇼
  • 사례 2 ...... 여기

내 코드입니다

나는 광고와 함께 일회성, 일회성과 같은 종류의 일을한다. 카운터를 보유하기 위해 사용자 기본값을 사용하기 만하면됩니다. 어쩌면 다음을 시도해보십시오. 아래의 코드는 조금 긴, 그래서 명확하게하기 위해 작성된 것입니다,하지만 당신은 가서 당신이 (무엇을하고 있는지 알고 일단을 강화 예. 대신 adCount = adCount + 1; 등의 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; 
} 
희망 사용할 수 있습니다