本文介绍了canDisplayBannerAds = YES导致Sprite Kit应用程序崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

处理我的第一个游戏并尝试在其中实施广告。

Working on my first game and trying to implement ads in to it.

我在viewController.h中声明了以下内容

I've declared the following in my viewController.h

#import <UIKit/UIKit.h>
#import <SpriteKit/SpriteKit.h>
#import <iAd/iAd.h>

@interface ViewController : UIViewController <ADBannerViewDelegate>

在我的实施文件中,我得到了以下(因为我需要横向布局而使用)

And in my implementation file I've Got the following (used because I need landscape layout)

- (void)viewWillLayoutSubviews
{


        [[NSUserDefaults standardUserDefaults] setInteger:0 forKey:@"Result"];
    [super viewWillLayoutSubviews];
    NSError *error;
    NSURL * backgroundMusicURL = [[NSBundle mainBundle] URLForResource:@"background-music-aac" withExtension:@"caf"];
    self.backgroundMusicPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:backgroundMusicURL error:&error];
    self.backgroundMusicPlayer.numberOfLoops = -1;
    [self.backgroundMusicPlayer prepareToPlay];
    [self.backgroundMusicPlayer play];

    // Configure the view.

    SKView * skView = (SKView *)self.view;
    if (!skView.scene) {
      skView.showsFPS = YES;
      skView.showsNodeCount = YES;

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

      // Present the scene.
      [skView presentScene:scene];
        self.canDisplayBannerAds = YES;

    }
}

然而,当我立即运行应用程序时崩溃(在下面记录) - 如果我改变self.canDisplayBannerAdds = NO;该应用程序运行正常 - 我有一种感觉这是非常简单,但我看不到它 - 任何人有任何想法?

However when I run the app instantly crashes (log below) - if I change self.canDisplayBannerAdds = NO; the app runs fine - I have a feeling this is ridiculously simple but I can't see it for looking - anyone got any ideas?

2014-02-13 22:40:20.605 SpriteKitSimpleGame[2812:70b] -[UIView scene]: unrecognized selector sent to instance 0xcb354c0
2014-02-13 22:40:20.608 SpriteKitSimpleGame[2812:70b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIView scene]: unrecognized selector sent to instance 0xcb354c0'
*** First throw call stack:
(
    0   CoreFoundation                      0x019fa5e4 __exceptionPreprocess + 180
    1   libobjc.A.dylib                     0x0177d8b6 objc_exception_throw + 44
    2   CoreFoundation                      0x01a97903 -[NSObject(NSObject) doesNotRecognizeSelector:] + 275
    3   CoreFoundation                      0x019ea90b ___forwarding___ + 1019
    4   CoreFoundation                      0x019ea4ee _CF_forwarding_prep_0 + 14
    5   SpriteKitSimpleGame                 0x00008169 -[ViewController viewWillLayoutSubviews] + 729
    6   UIKit                               0x0043321a -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 278
    7   libobjc.A.dylib                     0x0178f81f -[NSObject performSelector:withObject:] + 70
    8   QuartzCore                          0x0232e2ea -[CALayer layoutSublayers] + 148
    9   QuartzCore                          0x023220d4 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 380
    10  QuartzCore                          0x0232e235 -[CALayer layoutIfNeeded] + 160
    11  UIKit                               0x004ee613 -[UIViewController window:setupWithInterfaceOrientation:] + 304
    12  UIKit                               0x0040d177 -[UIWindow _setRotatableClient:toOrientation:updateStatusBar:duration:force:isRotating:] + 5212
    13  UIKit                               0x0040bd16 -[UIWindow _setRotatableClient:toOrientation:updateStatusBar:duration:force:] + 82
    14  UIKit                               0x0040bbe8 -[UIWindow _setRotatableViewOrientation:updateStatusBar:duration:force:] + 117
    15  UIKit                               0x0040bc70 -[UIWindow _setRotatableViewOrientation:duration:force:] + 67
    16  UIKit                               0x0040ad0a __57-[UIWindow _updateToInterfaceOrientation:duration:force:]_block_invoke + 120
    17  UIKit                               0x0040ac6c -[UIWindow _updateToInterfaceOrientation:duration:force:] + 400
    18  UIKit                               0x0040b9c3 -[UIWindow setAutorotates:forceUpdateInterfaceOrientation:] + 870
    19  UIKit                               0x0040efb6 -[UIWindow setDelegate:] + 449
    20  UIKit                               0x004e0737 -[UIViewController _tryBecomeRootViewControllerInWindow:] + 180
    21  UIKit                               0x00404c1c -[UIWindow addRootViewControllerViewIfPossible] + 609
    22  UIKit                               0x00404d97 -[UIWindow _setHidden:forced:] + 312
    23  UIKit                               0x0040502d -[UIWindow _orderFrontWithoutMakingKey] + 49
    24  UIKit                               0x0040f89a -[UIWindow makeKeyAndVisible] + 65
    25  UIKit                               0x003c2cd0 -[UIApplication _callInitializationDelegatesForURL:payload:suspended:] + 1851
    26  UIKit                               0x003c73a8 -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 824
    27  UIKit                               0x003db87c -[UIApplication handleEvent:withNewEvent:] + 3447
    28  UIKit                               0x003dbde9 -[UIApplication sendEvent:] + 85
    29  UIKit                               0x003c9025 _UIApplicationHandleEvent + 736
    30  GraphicsServices                    0x027b12f6 _PurpleEventCallback + 776
    31  GraphicsServices                    0x027b0e01 PurpleEventCallback + 46
    32  CoreFoundation                      0x01975d65 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 53
    33  CoreFoundation                      0x01975a9b __CFRunLoopDoSource1 + 523
    34  CoreFoundation                      0x019a077c __CFRunLoopRun + 2156
    35  CoreFoundation                      0x0199fac3 CFRunLoopRunSpecific + 467
    36  CoreFoundation                      0x0199f8db CFRunLoopRunInMode + 123
    37  UIKit                               0x003c6add -[UIApplication _run] + 840
    38  UIKit                               0x003c8d3b UIApplicationMain + 1225
    39  SpriteKitSimpleGame                 0x0000979d main + 141
    40  libdyld.dylib                       0x0310570d start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)


推荐答案

canDisplayBannerAdds 设置为YES时,您需要在控制器上使用 originalContentView 保持您的观点。

When canDisplayBannerAdds is set to YES, you need to use originalContentView on your controller to get hold of your view.

尝试使用以下代码来获取您的观点:

Try using the following code to get hold of your view:

SKView * skView = self.originalContentView;

这篇关于canDisplayBannerAds = YES导致Sprite Kit应用程序崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-27 07:31