Ios 从IAP从UIViewController中删除AdBannerView而无需重新启动应用程序
我有一个5个选项卡Ios 从IAP从UIViewController中删除AdBannerView而无需重新启动应用程序,ios,objective-c,iphone,nsnotification,adbannerview,Ios,Objective C,Iphone,Nsnotification,Adbannerview,我有一个5个选项卡UITabBarController,其中每个选项卡都是一个UIViewController。第一个选项卡称为时间线,第二个选项卡称为人员,最后一个选项卡称为更多 我已经在我的应用程序中实施了应用程序内购买s,在IAP之前,用户不能更改主题等。我在这个版本中要做的一件事是使用IAP删除iad 因此,在制作IAP之前,Timeline的底部有一个AdBannerView,当IAP从More选项卡购买后,我希望AdBannerView会立即从Timeline中删除 问题 现在实际发
UITabBarController
,其中每个选项卡都是一个UIViewController
。第一个选项卡称为时间线
,第二个选项卡称为人员
,最后一个选项卡称为更多
我已经在我的应用程序中实施了应用程序内购买
s,在IAP
之前,用户不能更改主题等。我在这个版本中要做的一件事是使用IAP
删除iad
因此,在制作IAP
之前,Timeline
的底部有一个AdBannerView
,当IAP
从More
选项卡购买后,我希望AdBannerView
会立即从Timeline
中删除
问题
现在实际发生的事情是,我转到更多
选项卡,购买IAP
并返回时间线
,而AdBannerView
仍然存在。如果我从时间线
选项卡移动到人员
选项卡并返回到时间线
选项卡,则AdBannerView
将被删除。或者,如果我在IAP
之后重新启动应用程序,则AdBannerView
将从时间线中删除。无论哪种方式,它都没有达到我预期的效果,即在我第一次从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;
}
}
此方法仅从视图调用,将出现
以NSLogs
为指南,在时间线
选项卡中,控制台显示BASIC
。当我转到More
选项卡,购买IAP
并返回到Timeline
选项卡时,视图将再次出现,该视图将触发displayiAdsOrNot
方法,这一次,我得到了NSLog
PRO
,因为NSUserDefault
iapsusccessful
现在是真的(这是在购买过程中完成的)
但是,此时仍会显示AdBannerView
我尝试过的
我已经尝试了很多方法来让它工作:
- 当购买完成时,创建一个
NSNotification
,在视图中将出现时间线
选项卡的方法。在该方法中,将self.adBanner
设置为nil
,将其从superview中删除,等等。选择器将被通知触发(在视图出现之前),但不会发生任何变化李>
- 我尝试了self.adBanner.delegate=self;self.adBanner=nil;[self.adBanner从SuperView中移除]代码>等,它是相同的
- 我尝试了
[self.timelineTableView reloadData]代码>
- 在这个类似的SO问题()之后,我甚至尝试将ivar设置为无效李>
- 我试着将
self.adBanner
放在屏幕外,但同样的事情正在发生;加载时间轴时,AdBannerView
仍在那里,直到我转到其他地方李>
我的视图将消失
,如下所示:
- (void)viewWillDisappear:(BOOL)animated
{
self.adBanner.delegate = nil;
self.adBanner=nil;
[self.adBanner removeFromSuperview];
}
这是为了使用共享的AdBannerViews
。self.adBanner
是在.h文件中创建的属性,我正在.m文件中使用@synthesis-adBanner=\u-adBanner
如果您对此有任何指导,我们将不胜感激 我已经解决了这个问题
通过删除视图将消失
并设置self.adBanner.hidden
=YES
如果成功
,并在通知中
,我成功地摆脱了AdBannerView
,而无需重新启动应用程序