Ho un problema serio su cui sto lavorando In acquisto di app e quando cerco di acquistare la prima volta funziona bene e per la seconda volta il mio trasferimento completo chiama due volte .. Non so perché ho avuto questa edizione.SKPayments Transazione completa chiamata due volte
Dopo aver ricevuto la ricevuta, chiamo il mio metodo di verifica e se la verifica va bene del server inviami il file audio in http responce e lo downlaod e quando riesco a scaricare il file, chiamo finishtransaction.
Ecco il mio codice
- (void)startPurchase {
[[SKPaymentQueue defaultQueue] addTransactionObserver:self];
if([SKPaymentQueue canMakePayments]) {
NSLog(@"IN-APP:can make payments");
SKProductsRequest *request = [[SKProductsRequest alloc] initWithProductIdentifiers: [NSSet setWithObject:myIdentifier]];
request.delegate = self;
NSLog(@"** Productdata is ** %@",myIdentifier);
[request start];
}
else {
NSLog(@"IN-APP:can't make payments");
loadingHUD.hidden=YES;
}
}
- (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response {
NSLog(@"IN productsRequest END %d",[response.products count]);
@try {
SKProduct *product = [response.products objectAtIndex:0];
SKPayment *newPayment = [SKPayment paymentWithProduct:product];
[[SKPaymentQueue defaultQueue] addPayment:newPayment];
NSLog(@"IN-APP:productsRequest END");
loadingHUD.hidden=YES; // Hide the Loading progress bar
}
@catch (NSException *exception) {
// Failed to purchase Hide the progress bar and Display Error Dialog
loadingHUD.hidden=YES;
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"error" message:@"Errror " 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
// [[SKPaymentQueue defaultQueue] finishTransaction: transaction];
NSLog(@"Purchase Transaction finish");
}
Nel metodo VerifyTransaction nel blocco scaricare il successo che io chiamo transazione finitura
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject)
{
[[SKPaymentQueue defaultQueue] finishTransaction: transaction]; // Finish the transaction
// NSLog(@"Successfully downloaded file to %@",[[NSString alloc] initWithData:operation.responseData encoding:NSASCIIStringEncoding]);
// Give alert that downloading successful.
NSLog(@"Successfully downloaded file to %@", destPath);
// NSLog(@"response: %@", operation.responseString); // Give alert that downloading successful.
// [self.target parserDidDownloadItem:destPath];
//loadingHUD.detailsLabelText = [NSString stringWithFormat:@"%@ %i%%",@"Downloading",100];
[loadingHUD hide:TRUE];
[DBHelper savePurchaseId:fileName]; // save the purchase itune id into local database to populate hover image of play button on main List
[self movieReceived];
}
funziona grazie mille –
@NSArray Benvenuti ... –
questo delegato non mi chiama – dineshprasanna