電話で実行するとうまく機能するiPhoneアプリがありますが、iPadの互換モードで実行すると起動時にクラッシュします。私は自分のプロジェクトで iAd を使用しています。具体的には、
Bannerviewcontroller.h および .m
iAd スイートからプログラムでバナーを表示します。
私の App Delegate では、いくつかのビュー コントローラーを次のようにラップします。
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
UIViewController *viewController1, *viewController2, *catVC3, *otherVC4;
UINavigationController *navController, *dognav, *catnav, *othernav;
viewController1 = [[FirstViewController alloc] initWithNibName:@"FirstViewController_iPhone" bundle:nil];
viewController2 = [[SecondViewController alloc] initWithNibName:@"SecondViewController_iPhone" bundle:nil];
catVC3 = [[catViewController alloc]initWithNibName:@"catViewController_iPhone" bundle:nil];
otherVC4 = [[otherViewController alloc]initWithNibName:@"otherViewController_iPhone" bundle:nil];
navController = [[UINavigationController alloc]initWithRootViewController:viewController1];
dognav = [[UINavigationController alloc]initWithRootViewController:viewController2];
catnav = [[UINavigationController alloc]initWithRootViewController:catVC3];
othernav = [[UINavigationController alloc]initWithRootViewController:otherVC4];
_tabBarController = [[UITabBarController alloc] init];
NSArray *controllers = [NSArray arrayWithObjects:navController,dognav,catnav,othernav,nil];
_tabBarController.viewControllers = controllers;
//wrap tabbar controller in adbanner controller
_bannerViewController = [[BannerViewController alloc] initWithContentViewController:_tabBarController];
self.window.rootViewController = _bannerViewController;
[self.window makeKeyAndVisible];
return YES;
次に、ここでクラッシュが発生します
Bannerviewcontroller.m
#import "BannerViewController.h"
@implementation BannerViewController
{
ADBannerView *_bannerView;
UIViewController *_contentController;
}
- (id)initWithContentViewController:(UIViewController *)contentController
{
self = [super init];
if (self != nil) {
_bannerView = [[ADBannerView alloc] init];
_bannerView.delegate = self;
_contentController = contentController;
}
return self;
}
- (void)loadView
{
UIView *contentView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
[contentView addSubview:_bannerView];
[self addChildViewController:_contentController];
[contentView addSubview:_contentController.view];
[_contentController didMoveToParentViewController:self];
self.view = contentView;
}
- (void)viewDidUnload
{
[super viewDidUnload];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return [_contentController shouldAutorotateToInterfaceOrientation:interfaceOrientation];
}
- (void)viewDidLayoutSubviews
{
if (UIInterfaceOrientationIsPortrait(self.interfaceOrientation)) {
_bannerView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierPortrait;
} else {
_bannerView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierLandscape;
}
CGRect contentFrame = self.view.bounds;
CGRect bannerFrame = _bannerView.frame;
if (_bannerView.bannerLoaded) {
contentFrame.size.height -= _bannerView.frame.size.height;
contentFrame.origin.y = _bannerView.frame.size.height;
bannerFrame.origin.y = contentFrame.size.height - contentFrame.size.height;
} else {
bannerFrame.origin.y = contentFrame.size.height;
}
_contentController.view.frame = contentFrame;
_bannerView.frame = bannerFrame;
}
- (void)bannerViewDidLoadAd:(ADBannerView *)banner
{
[UIView animateWithDuration:0.35 animations:^{
[self.view setNeedsLayout];
[self.view layoutIfNeeded];
}];
}
- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error
{
[UIView animateWithDuration:0.35 animations:^{
[self.view setNeedsLayout];
[self.view layoutIfNeeded];
}];
}
@end
この例外をスローします: * キャッチされない例外 'NSInvalidArgumentException' が原因でアプリを終了します。理由: '* -[__NSArrayM insertObject:atIndex:]: オブジェクトを nil にすることはできません'
何が起きてる?前もって感謝します!