2015-05-05 20 views
0

上啓動的應用程序崩潰,我必須在控制檯此錯誤:發送到實例|的無法識別的選擇器目標C

終止應用程序由於未捕獲的異常 「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 
} 

和其他代碼。 我嘗試了很多東西!所以我現在問你,我該如何解決這個問題? 提前致謝!

+0

通常有助於打開所有警告並使用靜態分析儀。在運行代碼之前向您顯示錯誤。還要設置Objective-C異常的斷點並檢查是誰調用了這個。 – gnasher729

+0

我該怎麼做? – VaultDesign

+0

當你在Xcode中調試它並且崩潰時,在控制檯中輸入'po

'來識別更多的對象發送消息。它是'打印對象'消息,將返回[對象描述]。你會看到'showInterstitial'消息是否真的被髮送到正確的對象(當然不是,所以崩潰的原因)。 –

回答

0

根據Chartboost documentation你是不是想表明間質的正確方法:

  • 要顯示靜態或插播視頻廣告:
  • // 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];
    0

    對一個實例調用showInterstitial,儘管它是一個類方法。它應該像[Chartboost showInterstitial...

    +0

    我有與hiddenadbanner相同的問題:'NSInvalidArgumentException',原因:' - [AppController hideAdBanner:]:無法識別的選擇器發送到實例0x7f870a412350 – VaultDesign

    +0

    我已經試過這個:[Chartboost showInterstitial];但它不起作用,同樣的問題。 – VaultDesign

    +0

    在示例應用程序中調用它的方式如下:'[Chartboost showInterstitial:CBLocationHomeScreen];'。關於你的其他問題:你在調用'[self hideAdBanner:YES];'但是我沒有看到一個方法的實現。所以你有這個錯誤是有道理的。 –

    相關問題