我无法在我的应用程序中查看iAd

时间:2014-03-11 03:26:48

标签: ios iad

在viewcontroller.m中

#import "ViewController.h"
#import "MyScene.h"

@import AVFoundation;

@interface ViewController ()
@property (nonatomic) AVAudioPlayer * backgroundMusicPlayer;
@end

@implementation ViewController

- (void)viewWillLayoutSubviews
{
    [super viewWillLayoutSubviews];
    NSError *error;
    NSURL * backgroundMusicURL = [[NSBundle mainBundle] URLForResource:@"loop" withExtension:@"wav"];
    self.backgroundMusicPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:backgroundMusicURL error:&error];
    self.backgroundMusicPlayer.numberOfLoops = 1;
    [self.backgroundMusicPlayer prepareToPlay];
    [self.backgroundMusicPlayer play];

    // Configure the view.
    SKView * skView = (SKView *)self.view;
    if (!skView.scene) {
      skView.showsFPS = YES;
      skView.showsNodeCount = NO;

      // Create and configure the scene.
      SKScene * scene = [MyScene sceneWithSize:skView.bounds.size];
      scene.scaleMode = SKSceneScaleModeAspectFill;





      // Present the scene.
      [skView presentScene:scene];

        self.canDisplayBannerAds = YES;

    }
}
- (BOOL)shouldAutorotate
{
    return YES;
}

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

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

#import <UIKit/UIKit.h>
#import <SpriteKit/SpriteKit.h>
#import <iAd/iAd.h>

@interface ViewController : UIViewController <ADBannerViewDelegate>

@end
在appDelegate.h

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


@interface AppDelegate : UIResponder <UIApplicationDelegate, ADBannerViewDelegate>

@property (strong, nonatomic) UIWindow *window;

@end

我根本无法查看我的iAd。

我觉得我错过了一些东西,但是我无法解决这个问题。

我的应用程序/游戏功能完美但我无法显示iAds。

我正在使用的文件是

appDelegate.h 
appDelegate.m
main storyboard
viewController.h
viewController.m
myScene.h
myScene.m
main.m
GAME-prefix.pch
gameOverScene.h
gameOverScene.m

1 个答案:

答案 0 :(得分:1)

看起来您实际上并没有在任何地方实施iAd横幅广告...您可以像这样使用它们:

-(void)bannerViewDidLoadAd:(ADBannerView *)banner {
    //user has internet connection, show the iAd      

    CGRect bannerFrame = banner.frame;
    CGRect screenBounds = [[UIScreen mainScreen] bounds];
    UIViewController *ViewController;

    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:1]; //animate the ad in
    [banner setAlpha:1]; //show the banner add
    [UIView commitAnimations];
}



- (void)bannerView:(ADBannerView *) banner didFailToReceiveAdWithError:error{
//banner view could not be loaded
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1]; //animate the ad out
[banner setAlpha:0]; //do not show the ad
[UIView commitAnimations];
}

您可以将其放在根ViewController文件中,然后将ADBannerView拖到您storyboard的视图中。然后右键点击ADBannerView,在Outlets下,将delegateFile's Owner或您视图底部的黄色小圈连接:

enter image description here

之后,当有互联网连接时,广告应该正确显示。