我在In App Purchase之后成功从我的Sprite Kit游戏中删除了iAd,但问题是需要重新启动应用才能让广告停止显示。
这让我相信视频或场景需要以某种方式刷新/重新加载(我已经尝试了很多方法),以便在购买In App之后iAd消失。
In App Purchase是在一个名为PurchasedViewController的单独类中进行的,我以模态方式呈现。
目前,我已尝试在购买完回根视图控制器后发送通知。
这是我的代码:
ViewController.m
#import "ViewController.h"
#import "Intro.h"
#import "PurchasedViewController.h"
#import <iAd/iAd.h>
#import "InAppManager.h"
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(reload)
name:@"reloadIntro"
object:nil];
// Configure the view.
SKView * skView = (SKView *)self.view;
// Create and configure the scene.
SKScene *scene = [Intro sceneWithSize:skView.bounds.size];
scene.scaleMode = SKSceneScaleModeAspectFill;
// Present the scene
[skView presentScene:scene];
}
-(void)reload {
// Reload the View/Scene to remove iAds
.....
}
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
//Display iAds
if ( [[InAppManager sharedManager] isFeature1PurchasedAlready] == FALSE) {
NSLog(@"iAds are showing");
ADBannerView *adView = [[ADBannerView alloc] initWithFrame:CGRectMake(0, self.view.frame.size.height - 480, 320, 50)];
[self.view addSubview:adView];
}
//Remove iAds
else if ( [[InAppManager sharedManager] isFeature1PurchasedAlready] == TRUE) {
NSLog(@"iAds have been removed");
ADBannerView *adView = [[ADBannerView alloc] initWithFrame:CGRectMake(0, self.view.frame.size.height - 480, 320, 50)];
adView.hidden = YES;
[adView removeFromSuperview];
}
}
PurchasedViewController.m
我不会在这里放置大量的应用内购买代码,因为我知道它有效并且我已经成功删除了Chartboost的广告。
-(void) unlockProduct1 {
if ( [[InAppManager sharedManager] isFeature1PurchasedAlready] == NO) {
NSLog(@"Product 1 was not bought yet");
[buyProduct1Button setBackgroundImage:[UIImage imageNamed:@"Remove_Ads"] forState:UIControlStateNormal];
}
else {
NSLog(@"Product 1 WAS bought");
[buyProduct1Button setBackgroundImage:[UIImage imageNamed:@"Purchased"] forState:UIControlStateNormal];
// Sending Notification to ViewController.m
NSLog(@"Did Send notification reloadIntro");
[[NSNotificationCenter defaultCenter] postNotificationName:@"reloadIntro" object:nil];
}
}
- (IBAction)dismissPurchasedVC:(UIButton *)sender {
[self dismissModalViewControllerAnimated:YES];
}
答案 0 :(得分:1)
这不会删除iAd视图:
//Remove iAds
else if ( [[InAppManager sharedManager] isFeature1PurchasedAlready] == TRUE) {
NSLog(@"iAds have been removed");
ADBannerView *adView = [[ADBannerView alloc] initWithFrame:CGRectMake(0, self.view.frame.size.height - 480, 320, 50)];
adView.hidden = YES;
[adView removeFromSuperview];
}
它的作用:它创建一个新的iAd视图,将其设置为隐藏,并将其从超级视图中删除(它从未被添加到其中)。实际的&#34;直播&#34; iAd视图的实例不受此影响。
您需要为现有的一个iAd视图提供参考(ivar):
@implementation ViewController
{
ADBannerView* _adView;
}
在创建广告横幅视图时分配参考:
_adView = [[ADBannerView alloc] initWithFrame:CGRectMake(0, self.view.frame.size.height - 480, 320, 50)];
[self.view addSubview:_adView];
稍后使用该引用删除广告横幅视图:
[_adView removeFromSuperview];
_adView = nil;