ios – [GADSlot状态]:无法识别的选择器发送到iphone中的实例

我是iOS开发的新手.

我正试图在我的phonegap应用程序中在iOS中实现admob广告,所以我用google搜索&发现了somveadmob without plugin.

遵循所有程序后,
我收到错误MyApp [2388:70b] *由于未捕获的异常’NSInvalidArgumentException’终止应用程序,原因:’ – [GADSlot状态]:无法识别的选择器发送到实例0x10415920’**

所以我谷歌关于&发现我必须更改其他链接器标志. (-ObjC)here

我试过了,但它没有用.

我收到了这个错误.

这个解决方案也不适合我. [GADSlot state]: unrecognized selector sent to instance

2014-04-21 13:04:41.252 MyApp[2388:70b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[GADSlot state]: unrecognized selector sent to instance 0x10415920'
*** First throw call stack:
(
 0   CoreFoundation                      0x038a85e4 __exceptionPreprocess + 180
 1   libobjc.A.dylib                     0x02acb8b6 objc_exception_throw + 44
 2   CoreFoundation                      0x03945903 -[NSObject(NSObject) doesNotRecognizeSelector:] + 275
 3   CoreFoundation                      0x0389890b ___forwarding___ + 1019
 4   CoreFoundation                      0x038984ee _CF_forwarding_prep_0 + 14
 5   MyApp                            0x0001a01e -[GADSlot isMakingRequest] + 36
 6   MyApp                            0x00019c7d -[GADSlot setAdType:andReloadRequest:] + 334
 7   MyApp                            0x00018a5e -[GADBannerView setAdSize:andReload:] + 512
 8   MyApp                            0x00019052 -[GADBannerView setAdSize:] + 62
 9   MyApp                            0x00019381 -[GADBannerView initWithAdSize:] + 171
 10  MyApp                            0x00003e17 -[MainViewController viewDidLoad] + 118
 11  UIKit                               0x0021c318 -[UIViewController loadViewIfRequired] + 696
 12  UIKit                               0x0021c5b4 -[UIViewController view] + 35
 13  MyApp                            0x00002997 -[AppDelegate application:didFinishLaunchingWithOptions:] + 763
 14  UIKit                               0x00102355 -[UIApplication _handleDelegateCallbacksWithOptions:isSuspended:restoreState:] + 309
 15  UIKit                               0x00102b95 -[UIApplication _callInitializationDelegatesForURL:payload:suspended:] + 1536
 16  UIKit                               0x001073a8 -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 824
 17  UIKit                               0x0011b87c -[UIApplication handleEvent:withNewEvent:] + 3447
 18  UIKit                               0x0011bde9 -[UIApplication sendEvent:] + 85
 19  UIKit                               0x00109025 _UIApplicationHandleEvent + 736
 20  GraphicsServices                    0x038062f6 _PurpleEventCallback + 776
 21  GraphicsServices                    0x03805e01 PurpleEventCallback + 46
 22  CoreFoundation                      0x03823d65 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 53
 23  CoreFoundation                      0x03823a9b __CFRunLoopDoSource1 + 523
 24  CoreFoundation                      0x0384e77c __CFRunLoopRun + 2156
 25  CoreFoundation                      0x0384dac3 CFRunLoopRunSpecific + 467
 26  CoreFoundation                      0x0384d8db CFRunLoopRunInMode + 123
 27  UIKit                               0x00106add -[UIApplication _run] + 840
 28  UIKit                               0x00108d3b UIApplicationMain + 1225
 29  MyApp                            0x000025fd main + 95
 30  MyApp                            0x00002595 start + 53
 )
libc++abi.dylib: terminating with uncaught exception of type NSException

请帮帮我.

的main.m

#import <UIKit/UIKit.h>

int main(int argc, char *argv[]) {

    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
    int retVal = UIApplicationMain(argc, argv, nil, @"AppDelegate");//It highlight this line when exception accoure.
    [pool release];
    return retVal;
}

MainViewController.m

- (void) viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    bannerView_ = [[GADBannerView alloc]initWithAdSize:kGADAdSizeSmartBannerPortrait];

    CGRect screenRect = [[UIScreen mainScreen] bounds];
    CGFloat screenWidth = screenRect.size.width;
    CGFloat screenHeight = screenRect.size.height;
    CGFloat screenXPos = (screenWidth/2);
    CGFloat screenYPos = screenHeight - kGADAdSizeBanner.size.height;
    [bannerView_ setCenter:CGPointMake(screenXPos, screenYPos)];
    bannerView_.adUnitID = MY_BANNER_UNIT_ID;
    bannerView_.rootViewController = self;
    [self.view addSubview:bannerView_];
    GADRequest *request = [GADRequest request];
    request.testing = NO;
    [bannerView_ loadRequest:request];

}

最佳答案 我认为,GADBannerView设置不正确.如果您有GADBannerView的源代码,请检查它并查看对象引用的来源.U应尝试在该方向上解决此错误.

检查你的admob版本,becoz GDBBannerview是Admob的一部分,这可能来自该代码.
或者尝试使用其他(较旧或较新版本)的admob api.

点赞