Dacomb
Dacomb

Reputation: 1

I cannot view iAds in my application

in 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

in viewcontroller.m

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

@interface ViewController : UIViewController <ADBannerViewDelegate>

@end

in appDelegate.h

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


@interface AppDelegate : UIResponder <UIApplicationDelegate, ADBannerViewDelegate>

@property (strong, nonatomic) UIWindow *window;

@end

I cannot get my iAds to view at all.

I feel i have missed something but i cannot work it out.

My app/game functions perfectly but I cannot get it to show iAds.

the files I am using are

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

Upvotes: 0

Views: 70

Answers (1)

Jojodmo
Jojodmo

Reputation: 23596

It looks like your not actually implementing the iAd banner methods anywhere... You could use them like this:

-(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];
}

You could put that in your Root ViewController file, then just drag an ADBannerView onto your view in your storyboard. Then right-click the ADBannerView, and under Outlets, connect delegate to your File's Owner, or the little yellow circle at the bottom of your view:

enter image description here

After that, ads should show correctly when there is internet connection.

Upvotes: 1

Related Questions