Note that there are some explanatory texts on larger screens.

plurals
  1. POiOS In app purchase doesn't call restoreTransaction on already purchased item
    primarykey
    data
    text
    <p>I am working on in app purchase with ios and i have few doubts, that doubts will be helpful for fresher like me so understand In app purchase.</p> <p>1)I got problem in my app if user "install my app into new device or same device if he remove my app before" at that time when user try to buy already purchase item my code does not call<code>restoreTransaction</code> in switch case of <code>updatedTransactions</code></p> <p>I get the message that <code>you ve already purchased this tap okay to downlaod it FREE Enviornment sandbox</code> and it call the <code>SKPaymentTransactionStatePurchased</code> case but it does not call the <code>SKPaymentTransactionStateRestored</code> what will the problem in my case..</p> <p>So i have implementing separate Restore Button to restore all video item already brought by user so just need to know that will it reject my app at apple store?</p> <p>2) For purchase of item it ask me password only one time and after that it doesn't ask me for password to purchase. it directly display the dialog box with confirm button but my project manager says it should ask for password for every item purchase.</p> <p>It ask for password every time when i try to restore the Purchase..strange.</p> <p>3) Currently i am testing in sandbox when i try to purchase with real apple id it display purchase failed(i have to use test account to test purchase as apple document says) but my project manager says that it should ask for new test username if you are testing in sandbox (as document said you have to sign out from setting manually but my project manager want to it should do automatically) ,</p> <p>So just need to ask that is it possible to sign-out and display sign box by coding ( i know its not possible but for information i ask)</p> <p>4)Currently my app is working in sandbox environment but do i need to change something for real purchase for my app?..or apple will automatically change sandbox to real purchase when apple validate my app and sign it and available on app store?</p> <p>5)i am validating transaction on my own server so i am sending sandbox 1 if i am on sandbox environment otherwise i have to send 0 ( currently i hardcode sandbox value to 1)so is there any method to detect environment is sandbox or real? </p> <p>Here is my purchase code and Restore button code any help is appreciated </p> <p>Purchase code </p> <pre><code>- (IBAction)PaymentButton:(id)sender { loadingHUD = [MBProgressHUD showHUDAddedTo:self.view animated:YES]; loadingHUD.labelText = NSLocalizedString(@"Loading", nil); [loadingHUD show:YES]; [self startPurchase];// call the restore Purchase method //[loadingHUD showWhileExecuting:@selector(startPurchase) onTarget:self withObject:nil animated:YES];// call the restore Purchase method } - (void)startPurchase { if([SKPaymentQueue canMakePayments]) { NSLog(@"IN-APP:can make payments"); [self requestProductData]; } else { NSLog(@"IN-APP:can't make payments"); loadingHUD.hidden=YES; } } - (void)requestProductData { NSLog(@"IN-APP:requestProductData"); SKProductsRequest *request = [[SKProductsRequest alloc] initWithProductIdentifiers: [NSSet setWithObject:myIdentifier]]; request.delegate = self; [request start]; NSLog(@"IN-APP:requestProductData END"); NSLog(@"Productdata is %@",myIdentifier); } - (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response { [[SKPaymentQueue defaultQueue] addTransactionObserver:self]; @try { SKProduct *product = [response.products objectAtIndex:0]; SKPayment *newPayment = [SKPayment paymentWithProduct:product]; [[SKPaymentQueue defaultQueue] addPayment:newPayment]; NSLog(@"IN-APP:productsRequest END"); } @catch (NSException *exception) { // Failed to purchase Hide the progress bar and Display Error Dialog loadingHUD.hidden=YES; UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Alert" message:@"Error in Product id can not purchase" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil]; [alertView show]; } } - (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions { for (SKPaymentTransaction *transaction in transactions) { switch (transaction.transactionState) { case SKPaymentTransactionStatePurchased: [self completeTransaction:transaction]; break; case SKPaymentTransactionStateFailed: [self failedTransaction:transaction]; break; case SKPaymentTransactionStateRestored: [self restoreTransaction:transaction]; default: break; } } } - (void) completeTransaction: (SKPaymentTransaction *)transaction { NSLog(@"Transaction Completed"); // Finally, remove the transaction from the payment queue. [self verifyReceipt:transaction]; // Call the verifyReceipt method to send transaction.bytes NSLog(@"Purchase Transaction finish"); [[SKPaymentQueue defaultQueue] finishTransaction: transaction]; } - (void) restoreTransaction: (SKPaymentTransaction *)transaction NSLog(@"Transaction Restored %@",transaction.originalTransaction.payment.productIdentifier); // You can create a method to record the transaction. // [self recordTransaction: transaction]; loadingHUD.hidden=YES; // You should make the update to your app based on what was purchased and inform user. // [self provideContent: transaction.payment.productIdentifier]; // Finally, remove the transaction from the payment queue. [[SKPaymentQueue defaultQueue] finishTransaction: transaction]; } - (void) failedTransaction: (SKPaymentTransaction *)transaction { loadingHUD.hidden=YES;// hide loadingHUD if (transaction.error.code != SKErrorPaymentCancelled) { // Display an error here. UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Purchase Unsuccessful" message:@"Your purchase failed. Please try again." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil]; [alert show]; } [[SKPaymentQueue defaultQueue] finishTransaction: transaction]; } </code></pre> <p>For restore it simple </p> <pre><code>-(void)startRestore { [[SKPaymentQueue defaultQueue] addTransactionObserver:self]; [[SKPaymentQueue defaultQueue] restoreCompletedTransactions]; } - (void) paymentQueueRestoreCompletedTransactionsFinished:(SKPaymentQueue *)queue { if ([queue.transactions count] == 0) { HUD.hidden=YES; UIAlertView *restorealert = [[UIAlertView alloc] initWithTitle:@"Restore" message:@"There is no products purchased by you" delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil]; [restorealert show]; } else { NSLog(@"received restored transactions: %i", queue.transactions.count); for (SKPaymentTransaction *transaction in queue.transactions) { NSString *temp = transaction.payment.productIdentifier; NSString *testID = [temp stringByReplacingOccurrencesOfString:projectIdString withString:@""]; NSString *productID = [testID stringByReplacingOccurrencesOfString:@"." withString:@""]; // remove Dot NSLog(@"cutted string is %@",productID); [purchasedItemIDs addObject:productID]; NSLog(@"** Purchased item is %@",purchasedItemIDs); } HUD.hidden=YES; HUD = [MBProgressHUD showHUDAddedTo:self.view animated:YES]; HUD.labelText = NSLocalizedString(@"Restoring", nil); [HUD showWhileExecuting:@selector(restorePurchasedItem) onTarget:self withObject:nil animated:YES];// call the restore Purchase method } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload