0

I am trying to implement a very simple iAd into my game and I am getting an error. I am new to Xcode and have trouble reading error codes. I've tried the exact same method in a new SpriteKit project and it worked perfectly. I'm guessing this must have something to do with my game.

The error is as follows.

2014-03-30 17:18:35.966 MyGame[672:60b] -[UIView setPaused:]: unrecognized selector sent to instance 0xa764120 2014-03-30 17:18:35.970 MyGame[672:60b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIView setPaused:]: unrecognized selector sent to instance 0xa764120' *** First throw call stack: ( 0 CoreFoundation 0x019901e4 __exceptionPreprocess + 180 1 libobjc.A.dylib 0x0170f8e5 objc_exception_throw + 44 2 CoreFoundation 0x01a2d243 -[NSObject(NSObject) doesNotRecognizeSelector:] + 275 3 CoreFoundation 0x0198050b ___forwarding___ + 1019 4 CoreFoundation 0x019800ee _CF_forwarding_prep_0 + 14 5 MyGame 0x00012331 -[AppDelegate applicationDidBecomeActive:] + 225 6 UIKit 0x002a6ca6 -[UIApplication _stopDeactivatingForReason:] + 329 7 UIKit 0x002ac891 -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 1378 8 UIKit 0x002c0f92 -[UIApplication handleEvent:withNewEvent:] + 3517 9 UIKit 0x002c1555 -[UIApplication sendEvent:] + 85 10 UIKit 0x002ae250 _UIApplicationHandleEvent + 683 11 GraphicsServices 0x025d9f02 _PurpleEventCallback + 776 12 GraphicsServices 0x025d9a0d PurpleEventCallback + 46 13 CoreFoundation 0x0190bca5 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 53 14 CoreFoundation 0x0190b9db __CFRunLoopDoSource1 + 523 15 CoreFoundation 0x0193668c __CFRunLoopRun + 2156 16 CoreFoundation 0x019359d3 CFRunLoopRunSpecific + 467 17 CoreFoundation 0x019357eb CFRunLoopRunInMode + 123 18 UIKit 0x002abd9c -[UIApplication _run] + 840 19 UIKit 0x002adf9b UIApplicationMain + 1225 20 MyGame 0x0001250d main + 141 21 libdyld.dylib 0x02ad8701 start + 1 ) libc++abi.dylib: terminating with uncaught exception of type NSException (lldb)

My ViewController.m is as follows

- (void)viewDidLoad
{
    [super viewDidLoad];

    // Configure the view.
    SKView * skView = (SKView *)self.view;
    skView.showsFPS = YES;
    skView.showsNodeCount = YES;

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

    self.canDisplayBannerAds = YES;
    // Present the scene.
    [skView presentScene:scene];
}
  • 1
    common problem, iAd replaces the view controller's view with its own, see here: http://stackoverflow.com/questions/19521677/what-does-the-iad-uiviewcontroller-category-candisplaybannerads-do – LearnCocos2D Mar 31 '14 at 06:36

2 Answers2

0

Try adding your code in viewWillLayoutSubViews...

- (void)viewWillLayoutSubviews 
{
    [super viewWillLayoutSubviews];
    SKView * skView = (SKView *)self.view;
    skView.showsFPS = YES;
    skView.showsNodeCount = YES;

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

    self.canDisplayBannerAds = YES;
    // Present the scene.
    [skView presentScene:scene];
}
maelswarm
  • 1,093
  • 4
  • 17
  • 35
  • I just tried it and it still gives an error but a different one. 2014-03-30 18:09:39.610 MyGame[397:60b] -[UIView presentScene:]: unrecognized selector sent to instance 0xa7674a0 2014-03-30 18:09:39.618 MyGame[397:60b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIView presentScene:]: unrecognized selector sent to instance 0xa7674a0' – user3438986 Mar 30 '14 at 22:10
  • When you comment out "self.canDisplayBannerAds = YES;" does it run? – maelswarm Mar 30 '14 at 22:13
  • Also, have you imported iAd.h? – maelswarm Mar 30 '14 at 22:15
  • Also, where do you create your banner? – maelswarm Mar 30 '14 at 22:18
  • Also try adding "self.canDisplayBannerAds = YES;" after "[skView presentScene:scene];". – maelswarm Mar 30 '14 at 22:20
  • If I comment out "self.canDisplayBannerAds = YES;", yes it does run. Yes I have imported iAd.h. I would like to create the banner on the bottom of the screen. And if I put "self.canDisplayBannerAds = YES;" after "[skView presentScene:scene];", I am still getting the error 'NSInvalidArgumentException', reason: '-[UIView presentScene:]: – user3438986 Mar 31 '14 at 01:08
  • My ViewController.h and ViewController.m are pretty clean and is almost the same as the one from a new SpriteKit project other than the fact that I imported AVFoundation for sounds. I'm not sure how this works but do you think the problem might be coming from the code I have in another file? – user3438986 Mar 31 '14 at 01:11
  • I have added StartGameScene.m to the top. I removed the displayHighScore and displayCoinWallet methods just so save room. MyScene is the scene that you actually play the game on. I would like ads to show on StartGameScene and not MyScene. – user3438986 Mar 31 '14 at 01:22
0

Apparently, the ViewController.m I had in my original question was correct. What caused the problem were a few lines I put in my AppDelegate.m to pause the game. That is why I was getting the 'NSInvalidArgumentException', reason: '-[UIView setPaused:]: error.

Here are two methods from my AppDelegate.m that contains the lines that caused the crash.

- (void)applicationWillResignActive:(UIApplication *)application
{
    // pause sprite kit
    SKView *view = (SKView *)self.window.rootViewController.view;
    view.paused = YES;

}

- (void)applicationDidBecomeActive:(UIApplication *)application
{
    //resume sprite kit
    SKView *view = (SKView *)self.window.rootViewController.view;
    view.paused = NO;
}

I removed these 4 lines and everything worked. Many thanks to those who helped.