2014-11-24 2 views
-2

Я интегрирую объявления в cocos2dx v3. Я пробовал 2 учебника для этого, но я получаю ошибку в нем. Мое приложение рушится во время выполнения всегда. Link 1Интеграция Admob в Cocos2dx v3 iOS

Link 2

Это то, что ошибка, я получаю

enter image description here

Редактировать

enter image description here

код

#import "BannerViewController.h" 
#import "GADBannerView.h" 

@interface BannerViewController() <GADBannerViewDelegate> 

@end 

@implementation BannerViewController { 
    GADBannerView *_bannerView; 
    UIViewController *_contentController; 
    Boolean _bannerLoaded; 
} 

- (instancetype)initWithContentViewController:(UIViewController *)contentController 
{ 
    self = [super init]; 
    if (self != nil) { 

     _bannerView = [[GADBannerView alloc] initWithAdSize: kGADAdSizeSmartBannerPortrait]; 
     _bannerView.adUnitID = @"ca-app-pub-1907540021489164/5304609731"; //REPLACE WITH YOUR OWN PUBLISHER ID 
     _bannerView.delegate = self; 
     _contentController = contentController; 
     _bannerLoaded = NO; 

    } 
    return self; 
} 


- (void)loadView 
{ 
    UIView *contentView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 
    [self addChildViewController:_contentController]; 
    [contentView addSubview:_contentController.view]; 
    [_contentController didMoveToParentViewController:self]; 
    [contentView addSubview:_bannerView]; 
    self.view = contentView; 
} 

#if __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_6_0 
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    return [_contentController shouldAutorotateToInterfaceOrientation:interfaceOrientation]; 
} 
#endif 

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation 
{ 
    return [_contentController preferredInterfaceOrientationForPresentation]; 
} 

- (NSUInteger)supportedInterfaceOrientations 
{ 
    return [_contentController supportedInterfaceOrientations]; 
} 

// For animation 
- (void)viewDidLayoutSubviews 
{ 
    CGRect contentFrame = self.view.bounds; 
    CGRect bannerFrame = CGRectZero; 
#if __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_6_0 
    bannerFrame = _bannerView.frame; 
#else 
    bannerFrame.size = [_bannerView sizeThatFits:contentFrame.size]; 
#endif 

    bannerFrame.origin.x = (contentFrame.size.width - bannerFrame.size.width)/2; 

    if (_bannerLoaded) { 
     //contentFrame.size.height -= bannerFrame.size.height; 
     bannerFrame.origin.y = contentFrame.size.height - bannerFrame.size.height; 
    } else { 
     bannerFrame.origin.y = contentFrame.size.height; 
    } 

    _contentController.view.frame = contentFrame; 
    _bannerView.frame = bannerFrame; 
} 

- (void)viewDidLoad { 
    [super viewDidLoad]; 

    _bannerView.rootViewController = self; 
    [self.view addSubview:_bannerView]; 

    GADRequest *request = [GADRequest request]; 
    [_bannerView loadRequest:request]; 
} 

- (void)adViewDidReceiveAd:(GADBannerView *)bannerView 
{ 
    NSLog(@"adViewDidReceiveAd"); 
    _bannerLoaded = YES; 
    [UIView animateWithDuration:0.25 animations:^{ 
     [self.view setNeedsLayout]; 
     [self.view layoutIfNeeded]; 
    }]; 
} 

- (void)adView:(GADBannerView *)view didFailToReceiveAdWithError:(GADRequestError *)error 
{ 
    NSLog(@"adView didFailToReceiveAdWithError"); 
    _bannerLoaded = NO; 
    [UIView animateWithDuration:0.25 animations:^{ 
     [self.view setNeedsLayout]; 
     [self.view layoutIfNeeded]; 
    }]; 
} 

- (void) hideBanner{ 
    [_bannerView removeFromSuperview]; 
} 

- (void) showBanner{ 
    [self.view addSubview:_bannerView]; 

    GADRequest *request = [GADRequest request]; 
    [_bannerView loadRequest:request]; 

    NSLog(@"Show Bannerr"); 
} 

- (void)dealloc { 
    _bannerView.delegate = nil; 
    [_bannerView release]; 
    [super dealloc]; 
} 

@end 

В AppController

_bannerViewController = [[BannerViewController Alloc] initWithContentViewController: _viewController];

Ошибка

2014-11-24 15:00:44.329 demococos2d iOS[4205:138334] <Google> Category methods are not loaded. Make sure you link the Google Mobile Ads library using one of the -ObjC, -force_load, or -all_load linker flags. See https://developers.google.com/mobile-ads-sdk/docs/#ios for more information. 
2014-11-24 15:00:44.856 demococos2d iOS[4205:138334] +[NSDecimalNumber gad_negativeOne]: unrecognized selector sent to class 0x1074e9618 
2014-11-24 15:00:44.864 demococos2d iOS[4205:138334] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+[NSDecimalNumber gad_negativeOne]: unrecognized selector sent to class 0x1074e9618' 
*** First throw call stack: 
(
    0 CoreFoundation      0x00000001086e53f5 __exceptionPreprocess + 165 
    1 libobjc.A.dylib      0x000000010804dbb7 objc_exception_throw + 45 
    2 CoreFoundation      0x00000001086ec40d +[NSObject(NSObject) doesNotRecognizeSelector:] + 205 
    3 CoreFoundation      0x00000001086447fc ___forwarding___ + 988 
    4 CoreFoundation      0x0000000108644398 _CF_forwarding_prep_0 + 120 
    5 demococos2d iOS      0x0000000104c529b8 -[GADStatisticDictionary decrementNumberForKey:shouldNotifyDelegate:] + 58 
    6 demococos2d iOS      0x0000000104c49a33 -[GADApplication init] + 461 
    7 demococos2d iOS      0x0000000104c4982f __35+[GADApplication sharedApplication]_block_invoke + 38 
    8 libdispatch.dylib     0x00000001099c77f4 _dispatch_client_callout + 8 
    9 libdispatch.dylib     0x00000001099b436d dispatch_once_f + 565 
    10 demococos2d iOS      0x0000000104c49807 +[GADApplication sharedApplication] + 102 
    11 demococos2d iOS      0x0000000104c45b0c +[GADSlot initialize] + 64 
    12 libobjc.A.dylib      0x000000010804e4d6 _class_initialize + 648 
    13 libobjc.A.dylib      0x00000001080576e1 lookUpImpOrForward + 351 
    14 libobjc.A.dylib      0x00000001080640d3 objc_msgSend + 211 
    15 demococos2d iOS      0x0000000104c43ca8 -[GADBannerView commonInitWithAdSize:] + 40 
    16 demococos2d iOS      0x0000000104c43eda -[GADBannerView initWithFrame:adSize:] + 177 
    17 demococos2d iOS      0x0000000104c440cb -[GADBannerView initWithAdSize:] + 142 
    18 demococos2d iOS      0x000000010474fec4 -[BannerViewController initWithContentViewController:] + 164 
    19 demococos2d iOS      0x0000000104750cc5 -[AppController application:didFinishLaunchingWithOptions:] + 757 
    20 UIKit        0x00000001057715a5 -[UIApplication _handleDelegateCallbacksWithOptions:isSuspended:restoreState:] + 234 
    21 UIKit        0x00000001057720ec -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 2463 
    22 UIKit        0x0000000105774e5c -[UIApplication _runWithMainScene:transitionContext:completion:] + 1350 
    23 UIKit        0x0000000105773d22 -[UIApplication workspaceDidEndTransaction:] + 179 
    24 FrontBoardServices     0x000000010b15d2a3 __31-[FBSSerialQueue performAsync:]_block_invoke + 16 
    25 CoreFoundation      0x000000010861aabc __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 12 
    26 CoreFoundation      0x0000000108610805 __CFRunLoopDoBlocks + 341 
    27 CoreFoundation      0x00000001086105c5 __CFRunLoopRun + 2389 
    28 CoreFoundation      0x000000010860fa06 CFRunLoopRunSpecific + 470 
    29 UIKit        0x0000000105773799 -[UIApplication _run] + 413 
    30 UIKit        0x0000000105776550 UIApplicationMain + 1282 
    31 demococos2d iOS      0x000000010475149f main + 111 
    32 libdyld.dylib      0x00000001099fc145 start + 1 
) 
libc++abi.dylib: terminating with uncaught exception of type NSException 
(lldb) 

Я также добавил -ObjC в других Linker Флаг

enter image description here

+0

Кажется, вы забыли установить флаг компоновщика -Objc, как указано в учебнике http://www.apusstudio.com/2014/04/cocos2d-x-with-admob-iad-mediation-in.html –

+0

I добавили -objc linker flag .. – Zohaib

+2

внесите свой код в вопрос, разместите его как текст не изображение – LearnCocos2D

ответ

2

Опция линкер -ObjC, не -objc. Дело важно.

EDIT: У вас также есть настройка на неправильном уровне (см. Левую сторону для действующих в настоящее время опций).

+0

Изменено и получена эта ошибка. clang: error: неизвестный аргумент: '-fno-ObjC-arc'. – Zohaib

+0

@ Zohaib Вы серьезно? – trojanfoe

+0

Да. То, что я получаю – Zohaib

0

Надеюсь, что я не опаздываю на вечеринку. Можете ли вы включить точку исключения исключения и посмотреть, какая строка она сломается. Оттуда было бы легче. Надеюсь, вы также добавили все необходимые рамки, необходимые для запуска admob. Если нет, проверьте эти рамки.

AdSupport AudioToolbox AVFoundation CoreGraphics CoreMedia CoreTelephony EventKit EventKitUI MessageUI StoreKit SystemConfiguration

Для получения дополнительной информации. Иди сюда. https://developers.google.com/admob/ios/quick-start

Смежные вопросы