如何让iAd在我的应用程序中全局查看?

问题描述:

我正在开发一个应用程序,我必须在我的应用程序的所有页面中显示iAds .. 我创建了UIView的子类,其中我正在初始化ADBannerView及其委托方法。如何让iAd在我的应用程序中全局查看?

但现在,如果我将其添加在窗口AppDelegate类它给我以下运行时错误 “ADBannerView必须是一个UIViewController管理视图层次的一部分” ..

我想,这是不是意味着我只能在UIViewController的子类文件中使用ADBanner?

如果是这样的话我该如何让它成为全球?

由于提前 SHREYA

+1

也请看看接受的答案在这里:http://*.com/questions/9422177/is-it-a-good-practice-to-delete-the-adbannerview-on-viewwilldisappear-and-add-它/ 9422360#9422360 – 2012-04-02 09:04:44

+0

嘿@ user1036925:如果你从下面的帖子得到答案。请接受它。 :) – 2012-04-02 09:39:58

+0

@shreya:把它放在appdelegate的窗口上,然后它可能.....! – 2012-10-16 17:13:36

在AppDelegate类中,你可以做一个共享对象。

- (ADBannerView *) sharedBannerView 
{ 
    if (_sharedBannerView == nil) 
    { 
     Class classAdBannerView = NSClassFromString(@"ADBannerView"); 

     if (classAdBannerView != nil) 
     { 
      _sharedBannerView = [[classAdBannerView alloc] initWithFrame:CGRectMake(0, 480, 320, 50)]; 

      // pre 4.2 doesn't have the new AdBannerSize constants. 
      if (&ADBannerContentSizeIdentifierPortrait != NULL) 
      { 
       [_sharedBannerView setRequiredContentSizeIdentifiers:[NSSet setWithObjects:ADBannerContentSizeIdentifierPortrait, ADBannerContentSizeIdentifierLandscape, nil]];    
      } 
      else 
      { 
       [_sharedBannerView setRequiredContentSizeIdentifiers:[NSSet setWithObjects:ADBannerContentSizeIdentifier320x50, ADBannerContentSizeIdentifier480x32, nil]];    
      } 
     } 
    } 

    ((ADBannerView *)_sharedBannerView).backgroundColor = [UIColor whiteColor]; 

    return _sharedBannerView; 
} 

并将此共享对象添加到任何需要显示iAd的视图中。 希望你得到它。

+0

嗨Neelam。 thanx为您的答复。我会执行它肯定.. – Shreya 2012-04-02 10:31:23

+0

@ user1036925:也看看这个苹果技术说明:[TN2286:实施共享的iAd横幅](https://developer.apple.com/library/ios/#technotes/ tn2286/_index.html#// apple_ref/DOC/UID/DTS40011212) – 2012-04-19 11:00:30