IAd in a set of sprites

I know that there is at least one question asking how to integrate iAd into a game with a set of sprites, but this is not what I am looking for. I am looking for a portrait version of how to do this. There seems to be absolutely 0 online tutorials on how to do this, so I came here. Can someone please tell me how easy it is to include iAd in a Sprite Kit game? I turned on canDisplayBannerAds and used the originalContentView property for my UIView, but I keep crashing that says

* The application terminated due to an unmapped exception 'NSInvalidArgumentException', reason: '- [ViewController originalContentView]: unrecognized selector sent to instance 0x10a0a7410'

any help would be appreciated and here is my code in my view of the controller

 - (void)viewWillLayoutSubviews { [super viewWillLayoutSubviews]; // Configure the view. SKView * skView = (SKView *)self.originalContentView; //skView.showsFPS = YES; //skView.showsNodeCount = YES; // Create and configure the scene. SKScene * scene = [MyScene sceneWithSize:skView.bounds.size]; scene.scaleMode = SKSceneScaleModeAspectFill; self.canDisplayBannerAds = YES; // Present the scene. [skView presentScene:scene]; } 
+6
source share
1 answer

For those who do not understand, and those intended for future reference, here is how I did it with my Sprite Kit game.

I had my game project created using the SpriteKit template in Xcode, then moved on to the project settings like this:

enter image description here

In the "Linking binaries to libraries" section, just click the + button and add the iAd infrastructure.

After that, go to your view controller for your Sprite Kit game, and then enter the following:

 // at the top #import <iAd/iAd.h> // do this in .m, above @implementation @interface YourViewControllerClassName () @property (nonatomic, strong) ADBannerView *banner; @end // after the implementation line // if you're needing to do it horizontally, do: - (void) viewWillLayoutSubviews { [super viewWillLayoutSubviews]; self.banner = [[ADBannerView alloc] initWithFrame:CGRectZero]; self.banner.delegate = self; [self.banner sizeToFit]; self.canDisplayBannerAds = YES; SKView *view = (SKView *)self.originalContentView; SKScene *scene = [[YourScene alloc] initWithSize:CGSizeMake(self.view.frame.size.width, self.view.frame.size.height)]; [view presentScene:scene]; } 

If you do iAd only in a normal portrait, you can do the above code, but you can also just use - (void) viewDidLoad instead ...

Now the delegate methods for iAd are displayed ...

Go to the code above the @implementation line and edit it

 // do this in .m, above @implementation @interface YourViewControllerClassName () <ADBannerViewDelegate> @property (nonatomic, strong) ADBannerView *banner; @end 

Now go to the implementation line and enter the following:

 // NOTE: THIS CODE CAME FROM APPLE MOSTLY // I DID EDIT IT, BUT THE CREDIT GOES TO APPLE DOCUMENTATION // ON IAD - (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error { if (banner.isBannerLoaded) { [UIView beginAnimations:@"animateAdBannerOff" context:NULL]; // Assumes the banner view is placed at the bottom of the screen. banner.frame = CGRectOffset(banner.frame, 0, banner.frame.size.height); [UIView commitAnimations]; } } - (void)bannerViewDidLoadAd:(ADBannerView *)banner { if (!banner.isBannerLoaded) { [UIView beginAnimations:@"animateAdBannerOn" context:NULL]; // Assumes the banner view is just off the bottom of the screen. banner.frame = CGRectOffset(banner.frame, 0, -banner.frame.size.height); [UIView commitAnimations]; } } 

This is all iAd requires to actually work in SpriteKit. Hope I helped those who read it.

+11
source

All Articles