如何在ios中存储和获取应用内购买的响应?

我已在我的项目中实施了应用内购买。 实施效果很好,但我有一个问题是存储响应。

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

但是当我回到上课时,我又回到了这堂课,然后又重新锁定了这个按钮,因为我无法存储响应。

我这样做:

.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]; } } 

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

非常欢迎来自专家的任何想法或建议。

你需要实现它。

购买成功后,在NSUserDefaults设置一个bool ,如:

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

在类的viewDidLoad中,写如:

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

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

我开发了非消费品的storekit 。 你可以尝试一下。 ;)

快乐的编码!