Reputation: 185
I have implemented in-app purchase in my project. The implementation worked well but I have a problem to store a response.
I unlocked the button and when I go through in-app purchase the button will be unlocked the response becomes true.
But when I go back the class from which I came this class, and jump back to this class again, I got the button locked again because I am not able to store response.
I am doning this:
.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];
}
}
how to store and fetch the response so that I can check the response?
Any Idea or suggestions from experts would be highly welcome.
Upvotes: 0
Views: 991
Reputation: 1323
I have developed storekit for non consumable product. You can try it. ;)
Happy coding!
Upvotes: 1
Reputation: 107131
You need to implement it like.
When the purchase is successful set a bool
in NSUserDefaults
like:
[[NSUserDefaults standardUserDefaults] setBool:YES ForKey:@"isPurchased"];
In the viewDidLoad
of the class, write like:
if([[NSUserDefaults standardUserDefaults] boolForKey:@"isPurchased"])
{
//Enable/show the button
}
else
{
//disable/hide button
}
This is a nice tutorial, please refer it also
Upvotes: 3