如何通过应用内购买删除广告? [英] How do I remove ads with In-App Purchase?

查看:92
本文介绍了如何通过应用内购买删除广告?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法找到购买后我的iAd未被删除的原因。

I am having trouble finding out why my iAd is not being removed after a purchase.

以下是我在iAd文件中尝试的内容:

Here is what I am trying in the file that has the iAd:

#define kInAppPurchaseUpgradeProductId @"kInAppPurchaseUpgradeProductId"

NSUserDefaults * defaults = [NSUserDefaults standardUserDefaults];
BOOL adsAreOff = [defaults boolForKey:kInAppPurchaseUpgradeProductId];

if (!adsAreOff)
{
    adView = [[ADBannerView alloc] initWithFrame:CGRectZero];
    adView.frame = CGRectOffset(adView.frame, 0, -50);
    adView.requiredContentSizeIdentifiers = [NSSet setWithObject:ADBannerContentSizeIdentifierPortrait];
    adView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierPortrait;
    CGRect adFrame = adView.frame;
    adFrame.origin.y = self.view.frame.size.height-adView.frame.size.height;
    adView.frame = adFrame;
    adView.backgroundColor = [UIColor clearColor];
    [self.view addSubview:adView];
    adView.delegate=self;
    self.bannerIsVisible=NO;
}
else 
{
    [adView removeFromSuperview];
}

以下是我在应用内购买代码中尝试的内容:

Here is what I am trying in my In-App Purchase code:

-(void)purchaseUpgrade
{
    SKPayment * payment = [SKPayment paymentWithProductIdentifier:kInAppPurchaseUpgradeProductId];
    [[SKPaymentQueue defaultQueue] addTransactionObserver:self];
    [[SKPaymentQueue defaultQueue] addPayment:payment];
}

-(IBAction)purchaseButtonTapped
{
    NSUserDefaults * defaults = [NSUserDefaults standardUserDefaults];
    [defaults setObject:adView forKey:kInAppPurchaseUpgradeProductId];

    // I tried this first, didn't work
    //[defaults setBool:TRUE forKey:kInAppPurchaseUpgradeProductId];

    [defaults synchronize];

    [self purchaseUpgrade];
}

这是在正确的地方处理,还是应该在 paymentQueue 方法?

Is this handled in the right place, or should it be in the paymentQueue method?

推荐答案

确保您正在同步 NSUserDefaults 在购买应用程序后设置密钥时:

Make sure that you're synchronizing your NSUserDefaults when you set the key after the application is purchased:

// After a purchase is made:
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:SOMETHING forKey:kInAppPurchaseUpgradeProductId]
[defaults synchronize];

这篇关于如何通过应用内购买删除广告?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆