在 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 的视图中。希望你能明白。