应用内购买自动续费交易恢复问题

发布于 2024-12-04 04:39:05 字数 1196 浏览 1 评论 0原文

我正在开发一个应用程序,用户可以在其中购买自动续订订阅。购买部分工作正常,但当用户删除应用程序并尝试恢复其购买时会出现问题。以下是我为处理该问题而编写的代码。

  1. 我已经给出了一个标题为“已经是订阅者”的按钮。当用户点击时,我调用以下代码。

    [[SKPaymentQueue defaultQueue] addTransactionObserver:self];
    [[SKPaymentQueuedefaultQueue]restoreCompletedTransactions];           
    
  2. 这就是我在 - (void) paymentQueue:(SKPaymentQueue *)queue UpdatedTransactions:(NSArray *)transactions 方法中处理恢复的方式。

     案例 SKPaymentTransactionStateRestored:
            持续时间 = [strDuration intValue];
            if(transaction.transactionReceipt != nil){
                收据 = [[NSString alloc] initWithData:[b64 dataByBase64EncodeFromData:transaction.transactionReceipt] 编码:NSASCIIStringEncoding];
                [userDefault setObject:transaction.transactionReceipt forKey:@"LastReceipt"];
                [队列完成事务:事务];
                [自调用ReceiptInfoImpl];
            }
            休息;
    
  3. 以下是恢复事务完成时的委托方法。

    -(void) paymentQueueRestoreCompletedTransactionsFinished:(SKPaymentQueue *)队列{ NSLog(@"已完成的事务已恢复"); }

是,当用户单击“已经是订阅者”按钮时,步骤 1. 会被调用,但步骤 2. 永远不会被调用。最后我可以在屏幕上看到消息“已完成交易已恢复”。

如果有人遇到类似的问题,请指导。

感谢您的阅读......

I am developing an application in which user can purchase auto-renewable subscription. Buying part is woking alright but problem occurs when user deletes the application and tries to restore his purchases. following is the code I wrote to handle that.

  1. I have given a button titled "Already a Subscriber". When user tap that I call following code.

    [[SKPaymentQueue defaultQueue] addTransactionObserver:self];
    [[SKPaymentQueue defaultQueue] restoreCompletedTransactions];           
    
  2. And this is how I handle restore in - (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions method.

            case SKPaymentTransactionStateRestored:
            duration = [strDuration intValue];
            if(transaction.transactionReceipt != nil){
                receipt = [[NSString alloc] initWithData:[b64 dataByBase64EncodeFromData:transaction.transactionReceipt] encoding:NSASCIIStringEncoding];
                [userDefault setObject:transaction.transactionReceipt forKey:@"LastReceipt"];
                [queue finishTransaction:transaction];
                [self callReceiptInfoImpl];
            }
            break;
    
  3. Following is delegate method when restore transaction is completed.

    -(void)paymentQueueRestoreCompletedTransactionsFinished:(SKPaymentQueue *)queue{
    NSLog(@"COMPLETED TRANSACTION RESTORED");
    }

Problem is that, when user clicks button "Already a subscriber" then Step 1. gets called but Step 2. never gets called. Finally I can see message "COMPLETED TRANSACTION RESTORED" on screen.

If anybody has faced similar problem then please guide.

Thanks for reading.....

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

满意归宿 2024-12-11 04:39:05

在你的类中,你必须实现回调
函数 paymentQueue:updatedTransactions:

此功能将在何时接收交易更新
它被制作了。因为即使应用程序处于运行状态,您的交易也会发生
已关闭,您应该准备好尽快接收这些通知
你打开应用程序。所以最好的地方是初始化它
applicationDidFinishLaunching 或等效方法。

来自此链接

Within your class, you have to implement the callback
function paymentQueue:updatedTransactions:

This function will receive updates on the transactions as and when
it’s made. Because your transactions take place even when the app is
closed, you should be ready to receive these notifications as soon as
you open the app. So the best place is to initialize it in
applicationDidFinishLaunching or equivalent method.

from this link

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文