2013-12-09 49 views
0

我用下面的代碼添加橫幅:iAd的橫幅崩潰的應用程序

- (void) addBunner { 
    CGRect frame = CGRectMake(0.0, 
           self.view.frame.size.height-50.0, 
           320.0, 
           50.0); 

    UIWindow* window = [UIApplication sharedApplication].keyWindow; 
    if (!window) { 
     window = [[UIApplication sharedApplication].windows objectAtIndex:0]; 
    } 

    ADBannerView *adView = [[ADBannerView alloc] initWithFrame:frame]; 

    adView.delegate=self;  
    [window addSubview:adView]; 
} 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    [self addBunner]; 
} 

加入iAd.framework。

應用程序在日誌中沒有任何消息時崩潰。問題在哪裏?

回答

3

的應用程序崩潰,因爲你是在窗口中添加旗幟。

原因:ADBannerView必須是由UIViewController管理的視圖層次結構的一部分。

因此,在UIViewController中添加橫幅。

1

這不是在您的應用程序中管理iAD的最佳方式。作爲其他類,有很多方法可以實現,它響應iAD Delegate,將iAD Banner添加到應用程序。

我建議在使用前閱讀蘋果文檔 - Apple iAD Documentation