【问题标题】:unrecognized selector sent to instance | Objective C无法识别的选择器发送到实例 |目标 C
【发布时间】:2015-05-05 07:56:22
【问题描述】:

应用程序在启动时崩溃,我在控制台中出现此错误:

由于未捕获的异常而终止应用程序 'NSInvalidArgumentException',原因:'-[Chartboost showInterstitial]: 无法识别的选择器发送到实例 0x7f844c9b74e0'

我的代码是:

#import "cocos2d.h"

#import "AppDelegate.h"
#import "IntroLayer.h"
#import "AppSpecificValues.h"
#import <RevMobAds/RevMobAds.h>

#import <Chartboost/Chartboost.h>


@implementation AppController
@synthesize gameCenterManager=gameCenterManager_, currentLeaderBoard=currentLeaderBoard_;
@synthesize window=window_, navController=navController_, director=director_;
@synthesize cb;
@synthesize nScore;

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // Create the main window
    window_ = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

    // Create an CCGLView with a RGB565 color buffer, and a depth buffer of 0-bits
    CCGLView *glView = [CCGLView viewWithFrame:[window_ bounds]
                                   pixelFormat:kEAGLColorFormatRGB565   //kEAGLColorFormatRGBA8
                                   depthFormat:0    //GL_DEPTH_COMPONENT24_OES
                            preserveBackbuffer:NO
                                    sharegroup:nil
                                 multiSampling:NO
                               numberOfSamples:0];

    director_ = (CCDirectorIOS*) [CCDirector sharedDirector];

    director_.wantsFullScreenLayout = YES;

    // Display FSP and SPF
//  [director_ setDisplayStats:YES];

    // set FPS at 60
    [director_ setAnimationInterval:1.0/60];

    // attach the openglView to the director
    [director_ setView:glView];

    // for rotation and other messages
    [director_ setDelegate:self];

    // 2D projection
    [director_ setProjection:kCCDirectorProjection2D];
//  [director setProjection:kCCDirectorProjection3D];

    // Enables High Res mode (Retina Display) on iPhone 4 and maintains low res on all other devices
    if( ! [director_ enableRetinaDisplay:YES] )
        CCLOG(@"Retina Display Not supported");

    // Default texture format for PNG/BMP/TIFF/JPEG/GIF images
    // It can be RGBA8888, RGBA4444, RGB5_A1, RGB565
    // You can change anytime.
    [CCTexture2D setDefaultAlphaPixelFormat:kCCTexture2DPixelFormat_RGBA8888];

    // If the 1st suffix is not found and if fallback is enabled then fallback suffixes are going to searched. If none is found, it will try with the name without suffix.
    // On iPad HD  : "-ipadhd", "-ipad",  "-hd"
    // On iPad     : "-ipad", "-hd"
    // On iPhone HD: "-hd"
    CCFileUtils *sharedFileUtils = [CCFileUtils sharedFileUtils];
    [sharedFileUtils setEnableFallbackSuffixes:NO];             // Default: NO. No fallback suffixes are going to be used

    [sharedFileUtils setiPhoneRetinaDisplaySuffix:@"-hd"];      // Default on iPhone RetinaDisplay is "-hd"
    [sharedFileUtils setiPadSuffix:@"-ipad"];                   // Default on iPad is "ipad"
    [sharedFileUtils setiPadRetinaDisplaySuffix:@"-ipad-hd"];   // Default on iPad RetinaDisplay is "-ipadhd"
    // Assume that PVR images have premultiplied alpha
    [CCTexture2D PVRImagesHavePremultipliedAlpha:YES];

    self.nScore = 0;

    //Revmobs
    [RevMobAds startSessionWithAppID:[[NSBundle mainBundle] objectForInfoDictionaryKey:@"RevMobAPI"]];

    // and add the scene to the stack. The director will run it when it automatically when the view is displayed.
    [director_ pushScene: [IntroLayer scene]]; 

    [self initGameCenter];

    // Create a Navigation Controller with the Director
    navController_ = [[UINavigationController alloc] initWithRootViewController:director_];
    navController_.navigationBarHidden = YES;

    // set the Navigation Controller as the root view controller
//  [window_ addSubview:navController_.view];   // Generates flicker.
    [window_ setRootViewController:navController_];

    // make main window visible
    [window_ makeKeyAndVisible];

    return YES;
}

-(void) lunchRevmobADLink
{
    [[RevMobAds session] openAdLinkWithDelegate:self];
}

- (void) setUpRevMob {
    [[RevMobAds session] showFullscreen];
}

-(void) launchChartboost
{
         // Initialize the Chartboost library
        [Chartboost startWithAppId:@"53be6ed01873dc9741aafa"
                      appSignature:@"fcd1715a73c97b22c5ad557323a59d7348476"
                          delegate:self];

    // Begin a user session. This should be done once per boot
    [cb startSession];

    [cb cacheInterstitial];

    [cb cacheMoreApps];
}

-(void) showChartboostInterestitial
{
    // Show an interstitial
    [[Chartboost sharedChartboost] showInterstitial];
}

-(void) showChartboostMoreApps
{
    [[Chartboost sharedChartboost] showMoreApps];
}

// Supported orientations: Landscape. Customize it for your own needs
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return UIInterfaceOrientationIsPortrait(interfaceOrientation);
}


// getting a call, pause the game
-(void) applicationWillResignActive:(UIApplication *)application
{
    if( [navController_ visibleViewController] == director_ )
        [director_ pause];
}

// call got rejected
-(void) applicationDidBecomeActive:(UIApplication *)application
{
    if( [navController_ visibleViewController] == director_ )
        [director_ resume];

    [self launchChartboost];

#ifdef FREE_VERSION
    [self showChartboostInterestitial];
    [self setUpRevMob];
    [self hideAdBanner:YES];

#endif
}

和其他代码。 我尝试了很多东西!所以我现在问你,我该如何解决这个问题??? 提前致谢!

【问题讨论】:

  • 通常有助于打开所有警告并使用静态分析器。在运行代码之前向您显示错误。还要在 Objective-C 异常上设置断点并检查谁在调用它。
  • 当您在 Xcode 中调试它并且它崩溃时,请在控制台中键入 po &lt;address ofinstance&gt; 以进一步识别向哪个对象发送消息。将返回 [对象描述] 的是“打印对象”消息。你会看到showInterstitial消息是否真的被发送到了正确的对象(肯定不是,所以是崩溃的原因)。
  • 但我真的需要写这个“po
    ”或者我需要替换文本“address of instance”??对不起我的无知。

标签: ios objective-c iphone


【解决方案1】:

根据Chartboost documentation,您并没有尝试以正确的方式显示插页式广告:

  1. 要展示静态或插页式视频广告:
// Show interstitial at location HomeScreen. See Chartboost.h for available location options.
[Chartboost showInterstitial:CBLocationHomeScreen];

在他们的 SDK 5.x 中删除了您的操作方式

所有对 [Chartboost sharedChartboost] 的引用现在都更改为 Chartboost:

  • [[Chartboost sharedChartboost] showInterstitial:CBLocationHomeScreen];现在是 [Chartboost showInterstitial:CBLocationHomeScreen];

【讨论】:

    【解决方案2】:

    您正在对实例调用 showInterstitial,尽管它是一个类方法。它应该类似于[Chartboost showInterstitial...

    【讨论】:

    • 我对 hideadbanner 有同样的问题:'NSInvalidArgumentException',原因:'-[AppController hideAdBanner:]: unrecognized selector sent to instance 0x7f870a412350
    • 我已经尝试过这个:[Chartboost showInterstitial];但它不起作用,同样的问题。
    • 在示例应用程序中,它的名称如下:[Chartboost showInterstitial:CBLocationHomeScreen];。关于您的其他问题:您正在调用[self hideAdBanner:YES];,但我没有看到该方法的实现。所以你得到这个错误是有道理的。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-28
    • 2012-07-24
    相关资源
    最近更新 更多