SKPaymentTransactionState
中告诉你,在你的请求被添加到服务器队列之前,SKPaymentTransactionStateFailed
。
@class SKPayment
enum {
SKPaymentTransactionStatePurchasing, // Transaction is being added to the server queue.
SKPaymentTransactionStatePurchased, // Transaction is in queue, user has been charged. Client should complete the transaction.
SKPaymentTransactionStateFailed, // Transaction was cancelled or failed before being added to the server queue.
SKPaymentTransactionStateRestored // Transaction was restored from user's purchase history. Client should complete the transaction.
}
typedef NSInteger SKPaymentTransactionState
在 SKPaymentTransaction
类参考错误讨论中提到:
除非 transactionState 被设置为 SKPaymentTransactionStateFailed
,否则 error 属性是未定义的。您的应用程序可以读取 error 属性以确定交易失败的原因。
因此,transaction.error.localizedDescription 是“无法连接到 iTunes Store”! 是一条常见的错误消息.. 我在测试我的 InApp Purchases 时也经常遇到这个错误消息。
以下是一些提示:
使用 SKProductsRequest
检索应用商店中的所有产品,并检查其 response.products
是否包含您请求的 productIdentifier
。
为此,请使用以下代码:
SKProductsRequest *request = [[SKProductsRequest alloc] initWithProductIdentifiers:[NSSet setWithArray:[objProducts allKeys]]]
//将产品标识符数组作为参数传递
[request start]
并在以下位置捕获响应:
- (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response{
NSArray *myProduct = response.products;
}
这样你就可以决定是否可以与应用商店通信,而且你的产品ID也在其中。
- 确保您在测试中使用 In App 测试用户帐户。
- 同时使用您为 In App 购买配置的相同 app-id 配置文件。
谢谢。