iAd仍然拒绝工作

时间:2014-11-28 04:57:32

标签: cocoa-touch iad

编辑:这里也是我的AppDelegate(部分内容)

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    self.window = [[UIWindow alloc]initWithFrame:[[UIScreen mainScreen]bounds]];
    GameViewController *gameViewController = [[GameViewController alloc]init];
    NSLog(@"NSLOG %@", [[gameViewController view]class]);
    _bannerViewController = [[BannerViewController alloc]initWithContentViewController:gameViewController];

    self.window.rootViewController = _bannerViewController;
    [self.window makeKeyAndVisible];

    return YES;
}

我即将放弃。在过去的几天里,我尝试了5种不同的方式来实现单一的iAd正确显示,就像Apple看起来一样简单,几乎100%的时间我看到没有广告或得到错误。我已经按照Apple文档完全。

我唯一的线索就是这两行

    GameViewController *gameViewController = [[GameViewController alloc]init];
    NSLog(@"NSLOG %@", [[gameViewController view]class]);

我的应用代表中有哪些内容。 NSLog给了我" UIView"。没有为什么?为什么它会成为一个UIView,它应该是一个SKView,因为GameViewController是由Apple为sprite kit预先编写的。怎么可能可能给我错误的对象?

我得到了'NSInvalidArgumentException', reason: '-[UIView scene]: unrecognized selector sent to instance 0x174191780'其他人建议通过originalContent声明来修复,但我已经有了这个并且它不起作用。

横幅视图控制器:

#import "BannerViewController.h"

NSString * const BannerViewActionWillBegin = @"BannerViewActionWillBegin";
NSString * const BannerViewActionDidFinish = @"BannerViewActionDidFinish";

@interface BannerViewController () <ADBannerViewDelegate>

@end

@implementation BannerViewController {
    ADBannerView *_bannerView;
    UIViewController *_contentController;
}

-(instancetype)initWithContentViewController:(UIViewController *)contentController{
    NSAssert(contentController != nil, @"Attempting to initialize a BannerViewController with a nil contentController.");

    self = [super init];
    if (self != nil) {
        _bannerView = [[ADBannerView alloc] initWithAdType:ADAdTypeBanner];
        _contentController = contentController;
        _bannerView.delegate = self;
    }
    return self;
}
-(void)loadView{
    UIView *contentView = [[UIView alloc]initWithFrame:[[UIScreen mainScreen]bounds]];

//Have also tried SKView *contentView = [[SKView alloc]initWithFrame:[[UIScreen mainScreen]bounds]];

    [contentView addSubview:_bannerView];
    [self addChildViewController:_contentController];
    [contentView addSubview:_contentController.view];
    [_contentController didMoveToParentViewController:self];

    self.view = contentView;
}
-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{
    return [_contentController preferredInterfaceOrientationForPresentation];
}
-(NSUInteger)supportedInterfaceOrientations{
    return [_contentController supportedInterfaceOrientations];
}
-(void)viewDidLayoutSubviews{
    CGRect contentFrame = self.view.bounds, bannerFrame = CGRectZero;

    bannerFrame.size = [_bannerView sizeThatFits:contentFrame.size];

    if(_bannerView.bannerLoaded){
        contentFrame.size.height -= bannerFrame.size.height;
        bannerFrame.origin.y = contentFrame.size.height;

    }else{
        bannerFrame.origin.y = contentFrame.size.height;
    }

    _contentController.view.frame = contentFrame;
    _bannerView.frame = bannerFrame;
}
-(void)bannerViewDidLoadAd:(ADBannerView *)banner{
    [UIView animateWithDuration:0.25 animations:^{
        [self.view setNeedsLayout];
        [self.view layoutIfNeeded];
    }];
}
-(void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error{
    [UIView animateWithDuration:0.25 animations:^{
        [self.view setNeedsLayout];
        [self.view layoutIfNeeded];
    }];
}
-(BOOL)bannerViewActionShouldBegin:(ADBannerView *)banner willLeaveApplication:(BOOL)willLeave{
    [[NSNotificationCenter defaultCenter]postNotificationName:BannerViewActionWillBegin object:self];
    return YES;
}
-(void)bannerViewActionDidFinish:(ADBannerView *)banner{
    [[NSNotificationCenter defaultCenter]postNotificationName:BannerViewActionDidFinish object:self];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

游戏视图控制器:

@interface GameViewController ()
@property (nonatomic, strong) IBOutlet UIView *contentView;

@end

@implementation GameViewController {

}
-(instancetype)init{
    self = [super init];
    if (self) {

    }
    return self;
}
-(void)viewDidLoad{
    //self.canDisplayBannerAds = YES;
    [super viewDidLoad];
}
-(void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
}
-(void)viewDidDisappear:(BOOL)animated{
    [super viewDidDisappear:animated];
}
-(void)viewDidLayoutSubviews{
}
-(void)viewWillLayoutSubviews{
    [super viewWillLayoutSubviews];
    SKView *skView = (SKView*)self.originalContentView;
    if (!skView.scene) {
        SKScene *scene = [GameScene sceneWithSize:skView.bounds.size];

        [skView presentScene:scene];
        //skView.showsPhysics = YES;


    }

}

- (BOOL)shouldAutorotate
{
    return NO;
}

- (NSUInteger)supportedInterfaceOrientations
{
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
        return UIInterfaceOrientationMaskPortrait;
    } else {
        return UIInterfaceOrientationMaskAll;
    }
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Release any cached data, images, etc that aren't in use.
}

- (BOOL)prefersStatusBarHidden {
    return YES;
}

1 个答案:

答案 0 :(得分:0)

我明白了。答案,正如我认为的那样,非常简单,令人难以置信的是Apple不会在他们的文档中发出某种警告,但话又许我可能只是一个菜鸟太多了,我们应该知道这些事情。

答案是init从未在GameViewController中调用,而是initWithCoder:被调用。一旦我NSLogged init方法并且看到它没有被调用,我就知道了。