2013-05-03 81 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設備。

享受編碼! :)