【发布时间】:2014-09-16 07:25:39
【问题描述】:
在应用内购买后,我已成功从我的 Sprite Kit 游戏中删除 iAd,但问题是需要重新启动应用才能停止显示广告。
这让我相信视图或场景需要以某种方式刷新/重新加载(我尝试了很多方法),以便 iAd 在应用内购买后消失。
应用内购买是在一个名为 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
我不会在这里放太多 In App Purchase 代码,因为我知道它可以工作,而且我已经成功删除了 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];
}
【问题讨论】:
-
不,您只需要确保 iAd 视图已被移除并解除分配。检查 Instruments,看看 iAd 视图是否仍然“活跃”。
-
我在
[adView removeFromSuperview];之后尝试了adView.delegate = nil;。如何在代码中取消分配 iAd? -
等等,我现在看到了...
-
当我在购买后关闭PurchasedVC 模式并返回到 SKScene 我在控制台中收到
NSLog(@"iAds have been removed");。另外,我尝试过 Instruments,但我真的不知道如何完全使用它。我正在使用 Allocations,但没有找到任何对 iAd 或 iAd 框架的引用。
标签: ios objective-c xcode sprite-kit iad