我最近刚读到全屏 iAd 只能在 iPad 上运行。ADInterstitialAd
本课程使用开发全屏 iAd。如何实现委托方法ADInterstitialAdDelegate
?
问问题
613 次
1 回答
0
您可以使用它来创建全屏 iAd
在 .H 文件中
进口
#import <iAd/iAd.h>
@interface ViewController : UIViewController<ADInterstitialAdDelegate>
{
ADInterstitialAd *interstitial;
}
在.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.
}
祝您编码愉快。干杯。
于 2014-04-11T19:33:20.790 回答