我曾經做過的閱讀周圍公平一點得到了廣告已發現以下幾個SO問題: using shared instance of ADBannerView across app with UITableViews How to make a single shared instance of iAd banner throughout many view controllers? AdBannerView shared across multiple views, including the rootviewcontroller, how?共享ADBannerView從AppDelegate中 - 如何從委託
我想有一個在didFinishLoading方法的AppDelegate類中加載的單個ADBannerView。希望這個ADBannerView可以被所有相關的ViewController檢索(通過導入AppDelegate.h),然後在用戶在VC之間移動時相應顯示。
,我已經實現的代碼如下:
AppDelegate.h @interface AppDelegate中:UIResponder
@property (strong, nonatomic) IBOutlet ADBannerView *adView;
@property (nonatomic, assign) BOOL bannerIsVisible;
- (ADBannerView *)sharedAdBannerView;
AppDelegate.m
ADBannerView *adView;
BOOL bannerIsVisible;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions(NSDictionary *)launchOptions
{
// create the iAdBannerView
adView = [[ADBannerView alloc] initWithFrame:CGRectZero];
adView.frame = CGRectOffset(adView.frame, 0, -50);
adView.requiredContentSizeIdentifiers = [NSSet setWithObject:ADBannerContentSizeIdentifier320x50];
adView.currentContentSizeIdentifier = ADBannerContentSizeIdentifier320x50;
adView.delegate=self;
self.bannerIsVisible=NO;
// Override point for customization after application launch.
return YES;
}
#pragma begin of iAdBannerView Delegate Methods
- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error
{
if (self.bannerIsVisible)
{
[UIView beginAnimations:@"animateAdBannerOff" context:NULL];
banner.frame = CGRectOffset(banner.frame, 0, -50);
[UIView commitAnimations];
self.bannerIsVisible = NO;
}
}
- (void)bannerViewDidLoadAd:(ADBannerView *)banner
{
if (!self.bannerIsVisible)
{
[UIView beginAnimations:@"animateAdBannerOn" context:NULL];
// banner is invisible now and moved out of the screen on 50 px
banner.frame = CGRectOffset(banner.frame, 0, 50);
[UIView commitAnimations];
self.bannerIsVisible = YES;
}
}
- (ADBannerView *)sharedAdBannerView
{
return adView;
}
我還試圖的變化使用[NSNotificationCenter defaultCenter] postNotificationName:方法,但最後我面臨同樣的問題:
問題: 在ViewController中,我想顯示ADBannerView如何從AppDelegate中檢索它?
我目前:
ADBannerView *banner = [[UIApplication sharedApplication] sharedAdBannerView];
[self.view addSubview:banner];
但是我得到錯誤的許多似乎無法避開它。
錯誤:UIApplication沒有可見的@interface聲明扇區sharedAdBannerView。
我敢肯定我錯過了一些非常基礎的東西。
任何幫助將不勝感激...謝謝,詹姆斯
這似乎是在迅速...不objective-c –