简体   繁体   English

应用程序iAD后应用程序崩溃但不在模拟器上崩溃

[英]App crash on device after config iAD but not on simulator

I am creating an app on cocos2d. 我正在cocos2d上创建一个应用程序。 i config the iAd but I don't know my app is crashing on device but when I run app on simulator it works fine. 我配置了iAd,但我不知道我的应用程序在设备上崩溃但是当我在模拟器上运行应用程序时,它工作正常。

Error: 错误:

[ADBannerView initWithAdType:]: unrecognized selector sent to instance  

Code: 码:

- (void)createAdBannerView {
    Class classAdBannerView = NSClassFromString(@"ADBannerView");
    if (classAdBannerView != nil) {

        _adBannerView = [[classAdBannerView alloc] initWithAdType:ADAdTypeBanner];

        [_adBannerView setPosition:ccp([[CCDirector sharedDirector] winSize].width/2, -33)];

        [_adBannerView setDelegate:self];

        [[[CCDirector sharedDirector] view] addSubview:_adBannerView];

    }
}

initWithAdType requires iOS 6.0 or above. initWithAdType 需要 iOS 6.0或更高版本。 If you are testing on an iOS 5.x device, you'll see the crash. 如果您在iOS 5.x设备上进行测试,您将看到崩溃。 Use the old way of initializing ADBannerViews (eg, initWithFrame) on older devices. 使用在旧设备上初始化ADBannerViews(例如,initWithFrame)的旧方法。

This is the iOS 6.0 declaration for initWithAdType: 这是initWithAdType的iOS 6.0声明:

- (id)initWithAdType:(ADAdType)type __OSX_AVAILABLE_STARTING(__MAC_NA, __IPHONE_6_0);

To support the old iOS5 way of creating an iAd banner, you'll need to add: 要支持旧的iOS5创建iAd横幅的方式,您需要添加:

#import <iAd/ADBannerView_Deprecated.h>

Example code: 示例代码:

ADBannerView *iAdView = nil;
if ([[ADBannerView class] instancesRespondToSelector:@selector(initWithAdType:)]) { // iOS 6.0
    iAdView = [[[ADBannerView alloc] initWithAdType:ADAdTypeBanner] autorelease];
} else { // iOS 4.x-5.x
    iAdView = [[[ADBannerView alloc] initWithFrame:CGRectMake(0, 0, appleWidth_, appleHeight_)] autorelease];
    iAdView.currentContentSizeIdentifier = isLandscape_ ? ADBannerContentSizeIdentifierLandscape : ADBannerContentSizeIdentifierPortrait;
}

I don't know why you are using this way, but the below is the one mentioned in Apple's Documentation: 我不知道你为什么使用这种方式,但下面是Apple的文档中提到的那个:

ADBannerView *adView = [[ADBannerView alloc] initWithFrame:CGRectZero];
adView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierPortrait;
adView.delegate = self;
[[[CCDirector sharedDirector] view] addSubview:adView];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM