2013-05-03 87 views
0

在我的应用程序中,我设置了两个不同的In App Purchase ID,可以说;Multiple In App Purchase - 如何在购买时设置不同的ID

com.myapp.purchase1 com.myapp.purchase2

的升级被设定为2个不同的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,即使在purchase1时,我也会这样称呼它;我怎样才能在purchase2订购时致电?

-(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]; 

} 
+0

这听起来像是一个经典的案例忘记添加一个“休息”在IBAction开关案例 – Stavash 2013-05-03 20:48:28

回答

0

看起来很明显,你忘记了这两条线在你的provideContent:forReceipt:函数中。无论何时您打电话,都会启用编号为@"com.myapp.purchase2"的产品。从你的函数中删除这些行。

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

嗨Guenis!好的,但是如果我从MKStore功能中删除这两行,那么我可以把它们放在哪里?因为如果用户购买com.myapp.purchase2,他们需要购买确认才能启用? – user1695971 2013-05-04 00:16:23

+0

提供if语句以了解购买哪种产品。 'if([productIdentifier isEqualToString:@“com.myapp.purchase2”])'如果这个语句不是真的不解锁'@“com.myapp.purchase2”]的内容'' – guenis 2013-05-04 00:21:01

+0

所以我会这样做MKStoreKit文件等; 'if([productIdentifier isEqualToString:@“com.myapp.purchase2”]){[NSUserDefaults standardUserDefaults] setBool:YES for forKey:@“com.myapp.purchase2”]; [[NSUserDefaults standardUserDefaults] synchronize];其他{ UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@“Upgrades”message:@“Successful Purchased”delegate:self cancelButtonTitle:@“ok”otherButtonTitles:nil,nil]; [alert show]; [alert release];' – user1695971 2013-05-04 00:22:25

0

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

享受编码! :)