2015-04-17 21 views
0

我有一个5选项卡UITabBarController,其中每个选项卡是UIViewController。第一个标签名为Timeline,第二个标签名为Person,最后一个标签名为More从IAP中从UIViewController中删除AdBannerView,而无需重新启动应用程序

我已经实现In-App Purchase s的我的应用程序,其中IAP之前,用户不能例如变化的主题,等一个我把这个版本的事情与IAP去除iAds

所以Timeline在底部有一个AdBannerViewIAP已经取得了面前,只要IAP已从More选项卡购买的,我期待的AdBannerViewTimeline马上被删除。

问题

我去More选项卡所发生的情况,现在是,购买IAP和回到TimelineAdBannerView仍然存在。如果我从Timeline选项卡移至Person选项卡并返回至Timeline选项卡,则会删除AdBannerView。或者,如果我在IAP之后重新启动应用程序,则AdBannerView将从Timeline中删除。无论哪种方式,它不是我所期望的,这是我第一次从More选项卡,在IAP之后回到Timeline选项卡时删除AdBannerView

下面是一些代码:

- (void)displayiAdsOrNot 
{ 
    NSLog(@"Display iAds or Not"); 
    if (![[NSUserDefaults standardUserDefaults] boolForKey:@"IAPSuccessful"]) 
    { 
     NSLog(@"BASIC"); 

     self.adBanner = [[self appdelegate] adBanners]; 
     self.adBanner.delegate = self; 

     if (IDIOM == IPAD) 
     { 
      NSLog(@"*** This is the iPad ***"); 
      [self.adBanner setFrame:CGRectMake(0, [[UIScreen mainScreen] bounds].size.height-80, 320, 50)]; 
      [self.adBanner setTranslatesAutoresizingMaskIntoConstraints:NO]; 

      [self.view addSubview:self.adBanner]; 
      NSLayoutConstraint *myConstraint =[NSLayoutConstraint 
               constraintWithItem:self.adBanner 
               attribute:NSLayoutAttributeLeading 
               relatedBy:NSLayoutRelationEqual 
               toItem:self.view 
               attribute:NSLayoutAttributeLeading 
               multiplier:1.0 
               constant:0]; 

      [self.view addConstraint:myConstraint]; 



      myConstraint =[NSLayoutConstraint constraintWithItem:self.adBanner 
                 attribute:NSLayoutAttributeTrailing 
                 relatedBy:NSLayoutRelationEqual 
                  toItem:self.view 
                 attribute:NSLayoutAttributeTrailing 
                 multiplier:1 
                 constant:0]; 

      [self.view addConstraint:myConstraint]; 

      myConstraint =[NSLayoutConstraint constraintWithItem:self.adBanner 
                 attribute:NSLayoutAttributeBottom 
                 relatedBy:NSLayoutRelationEqual 
                  toItem:self.view 
                 attribute:NSLayoutAttributeBottom 
                 multiplier:1 
                 constant:0]; 

      [self.view addConstraint:myConstraint]; 

     } 
     else 
     { 
      NSLog(@"*** THIS IS THE IPHONE ***"); 
      [self.adBanner setFrame:CGRectMake(0, [[UIScreen mainScreen] bounds].size.height-98, 320, 50)]; 
      [self.view addSubview:self.adBanner]; 
     } 

    } 
    else 
    { 
     NSLog(@"PRO"); 
     [self.adBanner removeFromSuperview]; 
     self.adBanner = nil; 
    } 
} 

这种方法只从viewWillAppear调用。

NSLogs为指导,在Timeline选项卡中,控制台显示BASIC。当我去More选项卡,购买IAP和回Timeline选项卡中,viewWillAppear火灾再次关闭的时候触发关闭displayiAdsOrNot方法,这一次,我得到了NSLogPRO因为NSUserDefaultIAPSuccessful现在是true(这是完成时购买通过)。

但是,此时仍然显示AdBannerView

我已经试过

我已经尝试了很多事情,试图得到这个工作:在进货时经过

  • 创建NSNotification,向监听器viewWillAppear方法Timeline选项卡。在该方法中,将self.adBanner设置为nil,将其从超级视图等中移除。选择器被Notification(在viewWillAppear之前)触发,但没有任何不同。
  • 我试过self.adBanner.delegate = self; self.adBanner = nil; [self.adBanner removeFromSuperview];等,它是同样的
  • 我已经试过[self.timelineTableView reloadData];
  • 在此之后相似的,所以问题(Reloading an SKScene or View to remove iAd after In App Purchase),我甚至试过伊娃设置没有影响。
  • 我试过将self.adBanner放置在屏幕外,但同样的事情正在发生;当时间轴被加载时,AdBannerView仍然存在,直到我去其他地方。

我有viewWillDisappear如下:

- (void)viewWillDisappear:(BOOL)animated 
{ 
    self.adBanner.delegate = nil; 
    self.adBanner=nil; 
    [self.adBanner removeFromSuperview]; 
} 

这是使用共享AdBannerViews的目的。 self.adBanner是在.h文件中创建的属性,我在.m文件中使用了@synthesize adBanner = _adBanner

任何有关这方面的指导真的很感激。

回答

0

我修复了这个问题。

通过消除viewWillDisappear和设置self.adBanner.hidden= YES如果IAPSuccessful并在Notification,我已经成功地摆脱AdBannerView的,无需重新启动应用程序。

相关问题