InSKPaymentTransactionState
告诉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
。您的应用程序可以读取错误属性以确定事务失败的原因。
所以,transaction.error.localizedDescription 是“无法连接到 iTunes Store”!是一般错误消息。在测试我的 InApp 购买时,我也经常收到此错误消息。
你可以做的一些提示是,
使用从应用商店检索所有产品SKProductsRequest
并检查其是否response.products
包含您的请求productIdentifier
。对于这种用途,
SKProductsRequest *request = [[SKProductsRequest alloc] initWithProductIdentifiers:[NSSet setWithArray:[objProducts allKeys]]];
//pass product identifier array as argument
[request start];
并捕获响应:
- (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response{
NSArray *myProduct = response.products;
}
这样您就可以决定是否可以与应用商店进行交流。并且您的产品 ID 在那里。
- 确保您使用应用内测试用户帐户进行测试。
- 并且您使用您在应用内购买中配置的相同应用 ID 配置。
谢谢