0

我已经在我的项目中实现了应用内购买。实现效果很好,但我在存储响应时遇到了问题。

我解锁了按钮,当我通过应用内购买时,按钮将被解锁,响应变为真。

但是当我回到我从这堂课上来的那个班,然后又跳回这堂课时,我的按钮又被锁定了,因为我无法存储响应。

我正在这样做:

.h file
bool isPurchased;






 -(void) successfulPurchase:(EBPurchase*)ebp restored:(bool)isRestore identifier:(NSString*)productId receipt:(NSData*)transactionReceipt
{
NSLog(@"ViewController successfulPurchase");

// Purchase or Restore request was successful, so...
// 1 - Unlock the purchased content for your new customer!
// 2 - Notify the user that the transaction was successful.

if (!isPurchased)
{
   // If paid status has not yet changed, then do so now. Checking
   // isPurchased boolean ensures user is only shown Thank You message
   // once even if multiple transaction receipts are successfully
   // processed (such as past subscription renewals).

   isPurchased = YES;


   if([[[NSUserDefaults standardUserDefaults] objectForKey:@"isPurchased"]     isEqualToString:@"true"]){

isPurchased = YES;
// do something

}
else{
isPurchased = NO;
//isFailed = NO;
 // do something  
}


   //-------------------------------------

   // 1 - Unlock the purchased content and update the app's stored settings.

   //-------------------------------------

   // 2 - Notify the user that the transaction was successful.

   NSString *alertMessage;

   if (isRestore) {
       // This was a Restore request.
       alertMessage = @"Your purchase was restored and the Game Levels Pack is now  unlocked for your enjoyment!";

   } else {
       // This was a Purchase request.
       alertMessage = @"Your purchase was successful and the Game Levels Pack is now   unlocked for your enjoyment!";


       //  if (my_unlock_button == TRUE) {
       buyButton.hidden=YES;                   // These are the buttons  I unlocked
       buybutton1.hidden=YES;                 // These are the buttons   I unlocked

       //}

   }

   UIAlertView *updatedAlert = [[UIAlertView alloc] initWithTitle:@"Thank You!"  message:alertMessage delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
   [updatedAlert show];
   [updatedAlert release];
}
}

如何存储和获取响应以便我可以检查响应?

非常欢迎专家提出任何想法或建议。

4

2 回答 2

3

你需要像这样实现它。

购买成功bool后在NSUserDefaultslike中设置一个:

[[NSUserDefaults standardUserDefaults] setBool:YES ForKey:@"isPurchased"];

viewDidLoad课堂上,这样写:

if([[NSUserDefaults standardUserDefaults] boolForKey:@"isPurchased"])
{
   //Enable/show the button
}
else
{
   //disable/hide button
}

这是一个很好的教程,也请参考

于 2013-04-22T11:07:00.177 回答
1

我为非消耗品开发了storekit。你可以试试看。;)

快乐编码!

于 2013-12-26T11:40:37.377 回答