0

我无法找出购买后我的 iAd 没有被删除的原因。

这是我在具有 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];
}

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

-(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方法中?

4

1 回答 1

1

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

// After a purchase is made:
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:SOMETHING forKey:kInAppPurchaseUpgradeProductId]
[defaults synchronize];
于 2012-06-24T03:38:27.147 回答