2013-08-19 21 views
6

私は深刻な問題を抱えています。アプリの購入時に、最初に購入しようとすると、2回目の完全トランザクションが2回呼び出されます。 なぜ私は知りませんこの問題。SKPayments完全なトランザクションが2回呼び出されました

私は私の検証方法を呼び出すと確認した後、サーバーよりも私には、http応答と私は正常にファイルをダウンロードするときに私はfinishtransactionを呼び出すと、オーディオファイルを送信します。ここで

は私のコードは、私はあなたのオブザーバーキューのようなその外観はまだ

- (void)paymentQueue:(SKPaymentQueue *)queue removedTransactions:(NSArray *)transactions 
{ 
    NSLog(@"Purchase removedTransactions"); 

    // Release the transaction observer since transaction is finished/removed. 
    [[SKPaymentQueue defaultQueue] removeTransactionObserver:self]; 
} 
古い製品IDが含まれている

答えて

8

[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]; 

} 

仕上げトランザクションを呼び出し、ダウンロード成功ブロックにVerifyTransaction方法で

- (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"); 

} 

です

取引が完了したら、商品IDを削除します。

+0

ありがとうございました –

+1

@ NSArrayようこそ... –

+0

この代理人は私に電話していません – dineshprasanna

1

私は次のことをやってしまった:

オブザーバーを削除する
if(contains(self.transactions, trans.transactionIdentifier) == false) { 
    self.transactions.append(trans.transactionIdentifier) 
    //Give the user the purchased product 
} 

は多少問題を軽減が、私はアプリで購入ボタンを「スパム」とき、私はまだ通過して時折ダブル呼び出しを持っていました。上記の解決策はそれを完全に解決しましたが、私のテストでは非常に堅牢なようです。

関連する問題