iAd不旋转

时间:2011-12-17 17:29:27

标签: iphone ios ipad orientation iad

我有1个iAd的通用应用。现在我需要支持两种方向..

我使用以下代码;

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {

    if ( &ADBannerContentSizeIdentifierPortrait != NULL) {
        // NEWER
        if (UIInterfaceOrientationIsLandscape(toInterfaceOrientation))
            adView_.currentContentSizeIdentifier = ADBannerContentSizeIdentifierLandscape;
        else
            adView_.currentContentSizeIdentifier = ADBannerContentSizeIdentifierPortrait;
    } else {
        // OLDER
        if (UIInterfaceOrientationIsLandscape(toInterfaceOrientation))
            adView_.currentContentSizeIdentifier = ADBannerContentSizeIdentifier480x32;
        else
            adView_.currentContentSizeIdentifier = ADBannerContentSizeIdentifier320x50;
    }
}

但是当我旋转到肖像时,我的应用程序崩溃并出现以下错误;

  

由于未捕获的异常而终止应用   'NSInternalInconsistencyException',原因:'currentContentSize必须   是requiredContentSizes之一; 'ADBannerContentSizeLandscape'是   不在{(       ADBannerContentSizePortrait)}'

我在IOS4.3模拟器上进行测试。

请帮帮我。谢谢。

1 个答案:

答案 0 :(得分:0)

试试这个:

if ([[[UIDevice currentDevice] systemVersion] compare:@"4.2" options:NSNumericSearch] == NSOrderedAscending) {

    adBanner.requiredContentSizeIdentifiers = [NSSet setWithObject:ADBannerContentSizeIdentifier320x50];

    adBanner.currentContentSizeIdentifier = ADBannerContentSizeIdentifier320x50;

    NSLog(@"below 4.2");

} else {

    adBanner.requiredContentSizeIdentifiers = [NSSet setWithObject:ADBannerContentSizeIdentifierPortrait];

    adBanner.currentContentSizeIdentifier = ADBannerContentSizeIdentifierPortrait;

    NSLog(@"4.2 or above");

}