2014-03-30 53 views
0

我想实现一个非常简单的iAd进入我的游戏,我得到一个错误。我是Xcode的新手,无法读取错误代码。我在一个新的SpriteKit项目中尝试了完全相同的方法,并且它完美地工作。我猜这肯定与我的比赛有关。UIView从实施iAd的错误

错误如下。

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 0x00-[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)

我ViewController.m是如下

​​
+1

常见问题,iAd用自己替换视图控制器的视图,请看这里:http://stackoverflow.com/questions/19521677/what-does-the-iad-uiviewcontroller-category-candisplaybannerads-do – LearnCocos2D

回答

0

显然,ViewController.m我在我的原问题是正确的。造成这个问题的原因是我在AppDelegate.m中放了几行暂停游戏。这就是为什么我得到'NSInvalidArgumentException',原因:' - [UIView setPaused:]:error。

以下是我的AppDelegate.m中包含导致崩溃的行的两种方法。

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

我删除了这4行,一切正常。非常感谢那些帮助过的人。

0

尝试增加在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]; 
} 
+0

我刚试过它和它仍然给出了一个错误,但一个不同的。 2014-03-30 18:09:39.610 MyGame [397:60b] - [UIView presentScene:]:无法识别的选择器发送到实例0xa7674a0 2014-03-30 18:09:39.618 MyGame [397:60b] ***终止应用程序由于未捕获的异常'NSInvalidArgumentException',原因:' - [UIView presentScene:]:无法识别的选择器发送到实例0xa7674a0' – user3438986

+0

当你注释掉“self.canDisplayBannerAds = YES;”它运行? – Roecrew

+0

另外,你有没有导入iAd.h? – Roecrew