某些用户在购买“应用内购买”时报告错误

时间:2019-02-18 17:07:26

标签: ios objective-c in-app-purchase

我的iOS应用程序存在一个非常棘手的问题。由于某种原因,很少有用户报告升级到高级版本时出错,付款仍可进行,但应用程序从未更新为高级。据我估计,有1-3%的用户有此问题。我无法重新创建这些用户使用我自己的设备遇到的错误。真的很难弄清楚是什么原因造成的。

但是用户报告说,当他们尝试重新购买特级产品时,他们从App Store中收到消息,表明该商品已经购买,并且将被恢复。但是话又说回来,它永远不会恢复。尝试恢复以前的购买时,也是同样的问题。

我将提供我认为有趣的代码,希望有人可能知道是什么导致了我的几个用户中这种行为。请记住,购买或恢复时不会出现该错误。但是,在购买或恢复产品后,即表示该应用程序没有得到更新。 (请参见代码中的“注释1”和“注释2”。)

- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions{
for(SKPaymentTransaction *transaction in transactions){
    switch(transaction.transactionState){
        case SKPaymentTransactionStatePurchasing:

            //called when the user is in the process of purchasing, do not add any of your own code here.
            NSLog(@"Transaction state -> Purchasing");

            break;
        case SKPaymentTransactionStatePurchased:
            //Purchase finished
            NSLog(@"Transaction state -> Purchased");

            if ([transaction.payment.productIdentifier isEqualToString:@"com.xxx.yyy.Premium"]) {
                //Comment 1: Method under never gets called in users with error
                [self upgradeToPremium];
            } else if ([transaction.payment.productIdentifier isEqualToString:@"com.xxx.yyy.250Coins"]) {
                [self addCoins:250];
            } else if ([transaction.payment.productIdentifier isEqualToString:@"com.xxx.yyy.600Coins"]) {
                [self addCoins:600];
            } else if ([transaction.payment.productIdentifier isEqualToString:@"com.xxx.yyy.1500Coins"]) {
                [self addCoins:1500];
            } else if ([transaction.payment.productIdentifier isEqualToString:@"com.xxx.yyy.4500Coins"]) {
                [self addCoins:4500];
            } else if ([transaction.payment.productIdentifier isEqualToString:@"com.xxx.yyy.10000Coins"]) {
                [self addCoins:10000];
            } else if ([transaction.payment.productIdentifier isEqualToString:@"com.xxx.yyy.25000Coins"]) {
                [self addCoins:25000];
            }

            //Comment 2: Method under never gets called in users with error
            [self finishPurchase];

            [[SKPaymentQueue defaultQueue] finishTransaction:transaction];


            break;
        case SKPaymentTransactionStateRestored:
            //Purchase restored
            NSLog(@"Transaction state -> Restored");

            if ([transaction.payment.productIdentifier isEqualToString:@"com.xxx.yyy.Premium"]) {
                [self upgradeToPremium];
            }


            [self finishPurchase];
            [[SKPaymentQueue defaultQueue] finishTransaction:transaction];

            break;
        case SKPaymentTransactionStateFailed:
            //called when the transaction does not finish

            if(transaction.error.code == SKErrorPaymentCancelled){
                NSLog(@"Transaction state -> Cancelled");
                //the user cancelled the payment ;(
            }

            [self finishPurchase];
            [[SKPaymentQueue defaultQueue] finishTransaction:transaction];

            break;
        case SKPaymentTransactionStateDeferred:
            NSLog(@"Transaction state -> Defferred");

            [self finishPurchase];
            [[SKPaymentQueue defaultQueue] finishTransaction:transaction];

            break;
    }
}
}


- (void)paymentQueueRestoreCompletedTransactionsFinished:(SKPaymentQueue *)queue {

int count = (int)queue.transactions.count;

if(count > 0) {
    for(SKPaymentTransaction *transaction in queue.transactions){
        if(transaction.transactionState == SKPaymentTransactionStateRestored){
            //called when the user successfully restores a purchase
            NSLog(@"Transaction state -> Restored");

            [self upgradeToPremium];
            [self finishPurchase];

            [[SKPaymentQueue defaultQueue] finishTransaction:transaction];

            break;
        }
    }
} else {
    [self finishPurchase];
}
}

- (void)upgradeToPremium {
    NSLog(@"PREMIUM");

    [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"PREMIUM"];
    [[NSUserDefaults standardUserDefaults] synchronize];
}

编辑:另一个选择是为遇到此错误的用户实施一种方法,以解锁高级用户。某种解决方法。我一直在想类似促销代码这样的东西来解锁高级会员。任何人都知道如何实现类似的东西吗?

0 个答案:

没有答案