如何在购买时发生错误时恢复应用内购买的iOS?

时间:2015-10-12 03:12:01

标签: ios in-app-purchase

发生错误时,我在应用内购物时出现问题。 我可能会在应用购买交易中被误解,所以如果出现问题请告诉我。 在支付队列中,观察者是相同的。

- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions{
for(SKPaymentTransaction *transaction in transactions){
    switch(transaction.transactionState)
    {
        case SKPaymentTransactionStatePurchased: 
            [self purchasedTransaction:transaction];
            break;
        case SKPaymentTransactionStateFailed: 
            [self failedTransaction:transaction];
            break;
        case SKPaymentTransactionStateRestored:
            [self restoreTransaction:transaction];
            break;
        default:
            break;
    }
}

并且restoreTransaction是

-(void)restoreTransaction:(SKPaymentTransaction *)transaction{
    NSLog(@"restore");
    [app hideIndicatorView];
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void) {
    [[SKPaymentQueue defaultQueue] finishTransaction: transaction];
    });

    [self verifyReceipt];
}

我使用看似

的verifyReceipt方法对in app货币收费
- (void)verifyReceipt
{
NSURL *receiptURL = [[NSBundle mainBundle] appStoreReceiptURL];
NSData *receipt = [NSData dataWithContentsOfURL:receiptURL];
if (!receipt) { /* No local receipt -- handle the error. */

    if ([UIAlertController class]) {

        UIAlertController *alert =   [UIAlertController
                                      alertControllerWithTitle:nil
                                      message:@"verify fail"
                                      preferredStyle:UIAlertControllerStyleAlert];
        UIAlertAction *ok = [UIAlertAction
                             actionWithTitle:@"OK"
                             style:UIAlertActionStyleDefault
                             handler:nil];
        [alert addAction:ok];
        [self presentViewController:alert animated:YES completion:nil];
    }else{
        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:nil message:@"verify fail" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [alert show];
    }


}else{

    //server confirmation with [receipt base64EncodedStringWithOptions:0]
}

当用户进行恢复事务时,它不起作用。 (通常,它发生在用户遇到网络问题或其他问题时......) 那么,请告诉我,我的工作流程是错误的?还是我错过了什么? 有没有办法测试恢复事务?

0 个答案:

没有答案