我有一个5选项卡UITabBarController
,其中每个选项卡是UIViewController
。第一个标签名为Timeline
,第二个标签名为Person
,最后一个标签名为More
。从IAP中从UIViewController中删除AdBannerView,而无需重新启动应用程序
我已经实现In-App Purchase
s的我的应用程序,其中IAP
之前,用户不能例如变化的主题,等一个我把这个版本的事情与IAP
去除iAds
。
所以Timeline
在底部有一个AdBannerView
的IAP
已经取得了面前,只要IAP
已从More
选项卡购买的,我期待的AdBannerView
从Timeline
马上被删除。
问题
我去More
选项卡所发生的情况,现在是,购买IAP
和回到Timeline
和AdBannerView
仍然存在。如果我从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
方法,这一次,我得到了NSLog
PRO
因为NSUserDefault
IAPSuccessful
现在是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
。
任何有关这方面的指导真的很感激。