How to Implement Interstitial Iads in Swift(Xcode 6.1)

How do you implement interstitial iads into a sprite kit game in swift?

the following code in your viewcontroller will do it. nothing more to it. you can invoke it with an NsNotofication or delegate from within your scene.

func fullScreenAd() {
if self.requestInterstitialAdPresentation() {
println("ad loaded")
}
}

Hide/Show iAds in Spritekit

Like Huygamer said, you're creating a new instance of a view controller so when you call your method [controller hidesBanner]; you're referring to another object.

The best approach here is to use NSNotificationCenter: https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/nsnotificationcenter_Class/Reference/Reference.html

And send a message to your viewcontroller whenever you want to hide or show your ad:

ViewController.m

 - (void)viewDidLoad
{

[super viewDidLoad];

//Add view controller as observer
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleNotification:) name:@"hideAd" object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleNotification:) name:@"showAd" object:nil];

// Configure the view.
SKView * skView = (SKView *)self.view;
skView.showsFPS = NO;
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;

adView = [[ADBannerView alloc] initWithFrame:CGRectZero];
adView.frame = CGRectOffset(adView.frame, 0, 0.0f);
adView.delegate=self;
[self.view addSubview:adView];

self.bannerIsVisible=NO;
}

//Handle Notification
- (void)handleNotification:(NSNotification *)notification
{
if ([notification.name isEqualToString:@"hideAd"]) {
[self hidesBanner];
}else if ([notification.name isEqualToString:@"showAd"]) {
[self showBanner];
}
}

And in your scene:

 [[NSNotificationCenter defaultCenter] postNotificationName:@"showAd" object:nil]; //Sends message to viewcontroller to show ad.

[[NSNotificationCenter defaultCenter] postNotificationName:@"hideAd" object:nil]; //Sends message to viewcontroller to hide ad.

Xcode 6.1 Swift issue - 'init()' is unavailable: superseded by import of -[NSObject init]

I have same problem, one way I found to suppress the error is to explicitly cast it:

leftBay = BayNode() as BayNode


Related Topics



Leave a reply



Submit