0

在我的应用程序上,我设置了 2 个不同的应用内购买 ID,可以说;

com.myapp.purchase1 com.myapp.purchase2

升级设置为 2 个不同的 IBAction,每个 IBAction 都有一个 alert.tag 以区分产品升级。但是,这部分工作正常。

购买 1 = 删除广告 购买 2 = 添加更多颜色

如果我购买,购买 2,它可以工作 - 广告仍然存在。如果我购买购买 1,它会删除广告,并解锁颜色 - 这是错误的。

购买 2 在此处链接到 NSUSerDefaults;

-(void)randImage
{
    currentIndex = (currentIndex+1) % ([[NSUserDefaults standardUserDefaults] boolForKey:@"com.myapp.purchase2"] ? 32 : 16);

        UIImage *myImage = [UIImage imageNamed:[NSString stringWithFormat:@"f%d.png",currentIndex +1]];

        [ColorsImage setImage:myImage];

}

这是来自 MKStoreManager.h

#define kConsumableBaseFeatureId @"com.myapp.colorsapp"
#define kFeatureAId @"com.myapp.purchase1"
#define kFeatureBId @"com.myapp.purchase2"

进行升级过程时,这是代码,我怀疑这是问题区域,但想不出我将如何解决?我在购买后调用 setBool ,我猜即使在购买 1 时也会调用它;我怎么只能在购买 2 时调用它?

-(void) provideContent: (NSString*) productIdentifier 
           forReceipt:(NSData*) receiptData
{
    if(ownServer != nil && SERVER_PRODUCT_MODEL)
    {
        // ping server and get response before serializing the product
        // this is a blocking call to post receipt data to your server
        // it should normally take a couple of seconds on a good 3G connection
        if(![self verifyReceipt:receiptData]) return;
    }

    NSRange range = [productIdentifier rangeOfString:kConsumableBaseFeatureId];     
    NSString *countText = [productIdentifier substringFromIndex:range.location+[kConsumableBaseFeatureId length]];

    int quantityPurchased = [countText intValue];
    if(quantityPurchased != 0)
    {

        int oldCount = [[NSUserDefaults standardUserDefaults] integerForKey:productIdentifier];
        oldCount += quantityPurchased;  

        [[NSUserDefaults standardUserDefaults] setInteger:oldCount forKey:productIdentifier];       
    }
    else 
    {
        [[NSUserDefaults standardUserDefaults] setBool:YES forKey:productIdentifier];       
    }

    [[NSUserDefaults standardUserDefaults] synchronize];

    if([_delegate respondsToSelector:@selector(productPurchased:)])
        [_delegate productPurchased:productIdentifier];



    [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"com.myapp.purchase2"];
    [[NSUserDefaults standardUserDefaults] synchronize];

UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"Upgrades" message:@"Successfully Purchased" delegate:self cancelButtonTitle:@"ok" otherButtonTitles:nil, nil];
[alert show];
[alert release];

}
4

2 回答 2

0

我想我回答你的问题迟到了,但对于其他人来说,他们可以试试这个 用于非消耗品的存储包。它支持 ios 5 及更高版本。它还支持 ios 6 托管内容,对于低于 ios 6 的设备,您只需添加服务器内容 url。

享受编码!:)

于 2013-12-26T12:34:42.390 回答
0

看起来很明显,您在provideContent:forReceipt:函数中忘记了这两行。@"com.myapp.purchase2"无论何时调用它,都会启用带有 id 的产品。从您的函数中删除这些行。

[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"com.myapp.purchase2"];
[[NSUserDefaults standardUserDefaults] synchronize];
于 2013-05-03T20:59:29.033 回答