ok so I got to make in app purchase for my app and it all works and unlocks the features that i want, but the sucky part is that whenever i get out of the main view (view1) and load another view(view2), when i come back to main view (view1), the stupid in app purchase is locked again.
the only way i can reunlock it is if i purchase it again. of course it says it's free download.
how can i make it so that when the app loads or comes from another view, it should be unlocked already if previously purchased (and i don't mean if the app is redownload it, just when it comes from another view).
thanks in advance guys.
here's my codes that i have
Code:
//the action that unlocks it and is set hidden after purchase
-(IBAction)purchaseAction{
SKPayment *payment = [SKPayment paymentWithProductIdentifier:@"partypack03"];
[[SKPaymentQueue defaultQueue] addTransactionObserver:self];
[[SKPaymentQueue defaultQueue] addPayment:payment];
}
- (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response{
SKProduct *validProduct = nil;
int count = [response.products count];
if (count > 0) {
validProduct = [response.products objectAtIndex:0];
}
else if (!validProduct){
NSLog(@"no in app purchase available");
}
}
- (void) paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions {
for (SKPaymentTransaction *transaction in transactions) {
switch (transaction.transactionState) {
case SKPaymentTransactionStatePurchasing:
NSLog(@"purchaseding");
break;
case SKPaymentTransactionStatePurchased:
[[SKPaymentQueue defaultQueue] finishTransaction:transaction];
purchased3player.hidden = YES;
purchased4player.hidden = YES;
NSLog(@"purchased show unlock");
break;
case SKPaymentTransactionStateRestored:
NSLog(@"stay unlock after reset");
purchased3player.hidden = YES;
purchased4player.hidden = YES;
[[SKPaymentQueue defaultQueue] finishTransaction:transaction];
break;
case SKPaymentTransactionStateFailed:
if (transaction.error.code != SKErrorPaymentCancelled) {
NSLog(@"payment error");
}
[[SKPaymentQueue defaultQueue] finishTransaction:transaction];
break;
}
if (transaction.transactionState != SKPaymentTransactionStatePurchasing) {
[[SKPaymentQueue defaultQueue] finishTransaction:transaction];
}
}
}
//inside the viewDidLoad
//load in app purchase
if ([SKPaymentQueue canMakePayments])
{
// Display a store to the user.
NSLog(@"parental control Disabled. You can purchase");
SKProductsRequest *productsRequest = [[SKProductsRequest alloc] initWithProductIdentifiers:[NSSet setWithObject:@"com.appstreetboys.AlmaDesnudaSpecialEdition"]];
productsRequest.delegate = self;
[productsRequest start];
}
else
{
// Warn the user that purchases are disabled.
NSLog(@"parental control enabled. You can't purchase");
}