我正在使用以下代码来设置共享的iAd标语。

AppDelegate.m

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    _adView = [[ADBannerView alloc]init];
}

ViewController.m
-(void) viewWillAppear:(BOOL)animated {
    AppDelegate *appdelegate = (AppDelegate *)[[UIApplication sharedApplication ]delegate];
    _adView = [appdelegate adView];
    _adView.delegate = self;
    self.canDisplayBannerAds = true;
}

- (void)bannerViewDidLoadAd:(ADBannerView *)banner {
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:1];
    [banner setAlpha:1];
    [UIView commitAnimations];
}

- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error {
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:1];
    [banner setAlpha:0];
    [UIView commitAnimations];
}
bannerView:didFailToReceiveAdWithError正在按预期方式被调用,但从未调用bannerViewDidLoadAd。我正在尝试在加载iAd标语时在屏幕上向上移动一些按钮。

最佳答案

您共享的横幅似乎不只是一个ADBannerView。看来您已经在@propertyADBannerView中为自己的AppDelegate.h设置了多个ViewController.h。另外,self.canDisplayBannerAds = true正在为您创建一个完全的新的和不同的 ADBannerViewself.canDisplayBannerAds = true可用于在应用程序中轻松实施iAd的简便方法。这将为您创建一个ADBannerView,并根据其是否从iAd网络接收广告来显示或隐藏ADBannerView。如果您计划自己实施viewDidLoad,则将其从ADBannerView中删除。

这是共享ADBannerView的实现应如下所示:

AppDelegate.h

#import <UIKit/UIKit.h>
@import iAd;

@interface AppDelegate : UIResponder <UIApplicationDelegate> {

}

@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) ADBannerView *iAdView;

@end

AppDelegate.m
-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    _iAdView = [[ADBannerView alloc]init];
    return YES;
}

ViewController.h
#import <UIKit/UIKit.h>
#import "AppDelegate.h"

@interface ViewController : UIViewController <ADBannerViewDelegate>

@end

ViewController.m
#import "ViewController.h"

@interface ViewController  ()

@end

@implementation ViewController  {
    AppDelegate *appDelegate;
}

-(void)viewDidLoad {
    [super viewDidLoad];

    appDelegate = (AppDelegate *)[[UIApplication sharedApplication ]delegate];
    appDelegate.iAdView.delegate = self;
    appDelegate.iAdView.frame = CGRectMake(0, 0, appDelegate.iAdView.frame.size.width, appDelegate.iAdView.frame.size.height);
    [self.view addSubview:appDelegate.iAdView];

    // You created another adView property in your ViewController.h?
    //_adView = [appdelegate adView];
    //_adView.delegate = self;

    // This will actually create ANOTHER ADBannerView
    // Do not use when creating your own ADBannerView
    //self.canDisplayBannerAds = true;
}

-(void)bannerViewDidLoadAd:(ADBannerView *)banner {
    NSLog(@"iAd LOADED");
    [UIView beginAnimations:nil context:NULL];
    appDelegate.iAdView.alpha = 1.0;
    [UIView commitAnimations];
}

-(void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error {
    NSLog(@"iAd FAILED");
    [UIView beginAnimations:nil context:NULL];
    appDelegate.iAdView.alpha = 0.0;
    [UIView commitAnimations];
}

关于ios - 共享iAd横幅bannerViewDidLoadAd没有被调用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/30677881/

10-12 01:48