多个应用内购买 - 如何在购买时设置不同的ID

时间:2013-05-03 20:39:33

标签: iphone ios xcode ipad

在我的应用程序中,我设置了2个不同的In App Purchase ID,让我们说;

com.myapp.purchase1 com.myapp.purchase2

升级设置为2个不同的IBActions,每个IBActions都有一个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];

}

2 个答案:

答案 0 :(得分:0)

很明显,您在provideContent:forReceipt:函数中忘记了这2行。无论何时调用它,都会启用标识为@"com.myapp.purchase2"的产品。从您的函数中删除这些行。

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

答案 1 :(得分:0)

我觉得我迟到了回答你的问题,但对于其他人,他们可以试试这个storekit 用于非消费品。它支持ios 5及以上版本。它还支持ios 6托管内容,对于ios 6以下设备,您只需添加服务器内容网址。

享受编码! :)