在我的应用程序上,我设置了 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];
}