17

I have a class that implements SKPaymentTransactionObserver. However when clicking a buy button, if the user is not signed into the app store they get an alert asking for an existing ID or to create a new one. If the use clicks cancel from this, or a subsequent login credentials alert, I receive no notification of that cancellation. I have an activity view covering the screen after the buy button is clicked so I really need to know if the login alert was cancelled.

I already test for the error code SKErrorPaymentCancelled and that works if the purchase process is cancelled after logging in. I'm testing on a device.

Any clues?

-UPDATE-

Apologies I forgot to mention that this only happened when attempting to restore transactions, and that reveals the answer: my lack of knowledge about the protocol.

4

4 回答 4

37

要在用户尝试取消恢复购买请求后检测取消事件,请执行:

- (void)paymentQueue:(SKPaymentQueue *)queue restoreCompletedTransactionsFailedWithError:(NSError *)error
{
    // test error.code, if it equals SKErrorPaymentCancelled it's been cancelled
}
于 2013-02-06T05:00:46.280 回答
10

在 Swift 3.0 中

public func paymentQueue(_ queue: SKPaymentQueue, restoreCompletedTransactionsFailedWithError error: Error) {
        print("Cancel Transaction");
    }
于 2017-03-14T15:27:25.567 回答
2

在斯威夫特 2.2

public func paymentQueue(queue: SKPaymentQueue, restoreCompletedTransactionsFailedWithError error: NSError) {
    print("Cancel Transaction")

}
于 2017-01-18T12:27:46.420 回答
0

当用户取消让他们输入 Apple ID 凭据的提示时,事务的状态为SKPaymentTransactionStateFailed. 这可能会令人困惑,因为如果用户自愿退出流程,则交易在技术上并未“失败”。要检测用户是否真正退出了进程,请检查事务错误(访问者)的错误代码是否transaction.error.codeSKErrorPaymentCancelled。如果不是,则该应用实际上在处理交易时遇到了问题。

于 2017-01-13T23:50:59.957 回答