gpt4 book ai didi

ios - 应用关闭后如何在应用购买中保留删除广告

转载 作者:行者123 更新时间:2023-11-29 12:13:03 24 4
gpt4 key购买 nike

我已通过应用内购买成功地从应用中删除了广告。

问题是,如果我关闭应用程序并重新打开。广告再次开始。

我有两个主要场景。 GameOverScene 和 GameScene。应用内购买发生在 GameOverScene 中。

GameOverScene.m :

- (void)OnRemoveADS {
[self showPurchaseAlert: IAP_Q_RemoveADS :0];

g_bRemoveADS = [[NSUserDefaults standardUserDefaults] boolForKey: @"REMOVEADS"];

// For HZInterstitialAd, HZVideoAd, and HZIncentivizedAd, just check the BOOL to see if an ad should be shown
if (!g_bRemoveADS) {
[HZInterstitialAd show];

[self removeBannerAds];
[self disableAds];
NSLog(@"Disable ads is called");
}
}

- (void)removeBannerAds {
HZBannerAdOptions *options = [[HZBannerAdOptions alloc] init];

[HZBannerAd placeBannerInView:self.view
position:HZBannerPositionBottom
options:options
success:^(HZBannerAd *banner) {
if (g_bRemoveADS) { // case (2)
// Just discard the banner
[banner setHidden: YES];
[banner removeFromSuperview];
banner = nil;

//_currentBannerAd = banner;

NSLog(@"Banner ad removed!GameOverScene");
} else {
// Keep a reference to the current banner ad, so we can remove it from screen later if we want to disable ads.
_currentBannerAd = banner;
}
NSLog(@"Ad Shown! GameOverScene");
}
failure:^(NSError *error) {
NSLog(@"Error = %@",error);
}];
}

- (void)disableAds {
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"REMOVEADS"];
[_currentBannerAd removeFromSuperview]; // case (3)
}

游戏场景.m:

-(id) init {
if (self = [super init]) {
if (!g_bRemoveADS) {
g_bRemoveADS=FALSE;
[[NSUserDefaults standardUserDefaults] setBool:g_bRemoveADS forKey:@"REMOVEADS"];
[[NSUserDefaults standardUserDefaults] synchronize];
} else {
g_bRemoveADS=TRUE;
[[NSUserDefaults standardUserDefaults] setBool:g_bRemoveADS forKey:@"REMOVEADS"];
[[NSUserDefaults standardUserDefaults] synchronize];
}
}
}

我尝试解决它的方法是在 AppDelegate.m 中使用来自 GameOverScene.m 的相同代码,这样当应用程序启动时它会删除广告。

AppDelegate.m :

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

g_bRemoveADS = [[NSUserDefaults standardUserDefaults] boolForKey: @"REMOVEADS"];

if (!g_bRemoveADS) {

[HZInterstitialAd show];

[self disableAds];
NSLog(@"Disable ads is called");
}
}

最佳答案

从我的角度来看,你有一个否定。

if (!g_bRemoveADS) { 在 GameOverScene.m 中应替换为 if (g_bRemoveADS) {

if (g_bRemoveADS) {
[HZInterstitialAd show];

[self removeBannerAds];
[self disableAds];
NSLog(@"Disable ads is called");
}

g_bRemoveADS 在设置相应的用户默认值时评估为 TRUE。设置后,您将调用 removeBannerAds 之类的东西,这似乎是停用操作。

关于ios - 应用关闭后如何在应用购买中保留删除广告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32806022/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com