我刚刚读到全屏iAd仅在iPad上有效。 ADInterstitialAd此类用于开发全屏iAd。如何在ADInterstitialAdDelegate中实现委托方法?

最佳答案

您可以使用它来创建全屏iAd

在.H文件中

进口

#import <iAd/iAd.h>

@interface ViewController : UIViewController<ADInterstitialAdDelegate>
{
    ADInterstitialAd *interstitial;
}

in。M文件
@interface ViewController ()

// Interstitials
- (void)cycleInterstitial;

@implementation ViewController

- (void)cycleInterstitial
{
    // Clean up the old interstitial...
    interstitial.delegate = nil;
    // and create a new interstitial. We set the delegate so that we can be notified of when
    interstitial = [[ADInterstitialAd alloc] init];
    interstitial.delegate = self;
}


#pragma mark ADInterstitialViewDelegate methods

// When this method is invoked, the application should remove the view from the screen and tear it down.
// The content will be unloaded shortly after this method is called and no new content will be loaded in that view.
// This may occur either when the user dismisses the interstitial view via the dismiss button or
// if the content in the view has expired.
- (void)interstitialAdDidUnload:(ADInterstitialAd *)interstitialAd
{
    [self cycleInterstitial];
}

// This method will be invoked when an error has occurred attempting to get advertisement content.
// The ADError enum lists the possible error codes.
- (void)interstitialAd:(ADInterstitialAd *)interstitialAd didFailWithError:(NSError *)error
{
    [self cycleInterstitial];
}

// if you want to show iAd while pushing view controller just use
- (IBAction)onSearchClick:(id)sender {
     if (interstitial.loaded) {
        //        [interstitial presentFromViewController:self]; // deprecated in iOS 6.
        [self requestInterstitialAdPresentation]; // it will load iAD Full screen mode.
    }
// do whatever you want to do.
}

祝您编码愉快。干杯。

08-06 03:31