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
Xcode: Could Not Load Modelio.Framework, Scenekit.Framework, etc
Disable Audio (And Interruption) with Mpmovieplayercontroller Using Swift
How to Create Type Erasing Weak References with Non-Optional Properties in Swift
Uisplitviewcontroller in Portrait on iPhone Always Show Master and Detail in iOS 8
How to Rounded the Corners When I Draw Rectangle Using Uibezierpath Points
Update Core Data Object Order - Not Working
Iaps Actually Validating the Receipt (Swift)
iOS Screen Sharing (Using Replaykit) Using Webrtc in Swift
Swift 3 and Firebase: Retrieve Auto Id Value from Snapshot
How to Convert a Float Value to Byte Array in Swift
Proper Model for Multiple Alamofire Requests for Multiple Websites
How to Pass an Error Pointer in the Swift Language
Get an Error When Trying to Get All the Photos from Phassetcollection.Fetchassetcollections