I am working on buying an application using ios, and I have little doubt that doubts will be useful for a more recent one, like me, so understand about buying an application.
1) I had a problem in my application if the user “installed my application on a new device or the same device if he uninstalls my application earlier”, while the user is trying to buy a purchase already, my code does not call restoreTransaction in the switch updatedTransactions
I get a message that you ve already purchased this tap okay to downlaod it FREE Enviornment sandbox and it causes the SKPaymentTransactionStatePurchased case, but it does not call SKPaymentTransactionStateRestored , which will be a problem in my case ..
So, I have a separate Restore button for restoring the entire video item that the user has already brought in, so you just need to know that he will reject my application in the Apple store?
2) To purchase goods, he asks for a password only once, and after that he does not ask me for a password for the purchase. it directly displays a dialog box with a confirmation button, but my project manager says that he should ask for a password for each purchase of goods.
It asks for a password every time I try to restore Purchase..strange.
3) I am currently testing in the sandbox when I try to buy with a real apple identifier on which it was not possible to display the purchase (I should use a test account to verify the purchase, as stated in the Apple document), but my project manager says that he should ask new ones to check the username if you are testing in the sandbox (the document says that you need to exit the settings manually, but my project manager wants it to run automatically),
So you just need to ask if it is possible to release and display the window using encoding (I know this is not possible, but for the information I ask)
4) My application is currently running in a sandbox environment, but do I need to change something for a real purchase for my application? .. or does the apple automatically change the sandbox to a real purchase when the apple checks my application and signs it up and is available in the app store ?
5) I check the transaction on my own server, so I send the sandbox 1 if I am in the sandbox environment, otherwise I need to send 0 (currently the hard code value for hard code is 1), so is there any method to detect the environment - is it a sandbox or real?
Here is my purchase code and button code Restore any help is welcome
Purchase 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]; }
It’s easy to recover
-(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:@""];