2011-04-29 95 views
0

我注意到我的iAd导致iOS 3.2崩溃。我在构建设置中很弱链接。它在我的createAdBanner方法中崩溃iAd崩溃3.2

NSString *contentSize; 

if (&ADBannerContentSizeIdentifierPortrait != nil) { 
    contentSize = UIInterfaceOrientationIsPortrait(self.interfaceOrientation) ? ADBannerContentSizeIdentifierPortrait : ADBannerContentSizeIdentifierLandscape; 
} 
else { 
    contentSize = UIInterfaceOrientationIsPortrait(self.interfaceOrientation) ? ADBannerContentSizeIdentifier320x50 : ADBannerContentSizeIdentifier480x32; 
} 

这是出现的错误。

This GDB was configured as "x86_64-apple-darwin".sharedlibrary apply-load-rules all 
     Attaching to process 4681. 
     Assertion failed: (cls), function getName, file /SourceCache/objc4_Sim/objc4-427.1.1/runtime/objc-runtime-new.m, line 3939. 
     Assertion failed: (cls), function getName, file /SourceCache/objc4_Sim/objc4-427.1.1/runtime/objc-runtime-new.m, line 3939. 
     Current language: auto; currently objective-c 
     (gdb) 

我以为你能够在3.2上运行iAds,如果你弱链接。任何想法或建议?

回答

1

除了弱链接之外,您还必须检查设备上是否有广告类可用。要做到这一点,你可以用下面来测试类的存在:

Class adClass = NSClassFromString(@"AdBannerView"); 

if(adClass){ 
    //ads are available so optionally show them 
}else{ 
    // ads are not available 
} 

要检查特定方法,你这样做:

BOOL methodExists = [someObject respondsToSelector:@selector(selectorToTestName:)]; 

if(methodExists){ 
    //Safe to call selector 
}else{ 
    //The selector doesn't exist in this version of iOS. 
} 

你也可以只使用上述说法,“内联”的布尔检查:以下链接它给更清楚

if([someObject respondsToSelector:@selector(selectorToTestName:)]){ 
    //Safe to call selector 
}else{ 
    //The selector doesn't exist in this version of iOS. 
} 
+0

我收到一个错误,可以在viewdidload中完成吗?特别是Class adClass = ...应该放在哪里。 – Vikings 2011-04-29 16:43:15

+0

@ Vikings1201 - 你有什么错误?这段代码应该在'viewDidLoad'中工作。 – Moshe 2011-04-29 16:47:08

+0

好的,我解决了这个错误,但是如果可能有广告,它从来没有进入声明的if部分。所以广告从不显示。 – Vikings 2011-04-29 17:14:32

0

显示广告ADBannerViewcan在4.0及以上使用。查看苹果文档

0

使用甚至在IOS 3.0+ IAD Tutorial你必须输入_weak_framework的iAd在linkingFlags至极的是使用可用的目标。一旦通过链接。