我正在使用应用内购买的应用程序直到交易部分。
启动时我有一个purchaseViewController
来调用getProductInfo
:
-(void)getProductInfo: (CC3DeviceCameraOverlayUIViewController *) viewController
{
_homeViewController = viewController;
if ([SKPaymentQueue canMakePayments])
{
SKProductsRequest *request = [[SKProductsRequest alloc]
initWithProductIdentifiers:
[NSSet setWithObject:self.productID]];
request.delegate = self;
[request start];
}
else
_productDescription.text =
@"Please enable In App Purchase in Settings";
}
哪个成功了。然后我有一个按钮来拨打buyProduct
:
- (IBAction)buyProduct:(id)sender {
SKPayment *payment = [SKPayment paymentWithProduct:_product];
if(_myQueue == nil) {
_myQueue = [SKPaymentQueue defaultQueue];
}
[_myQueue addPayment:payment];
NSLog(@"buyproduct happening %@", _product.localizedTitle);
}
这也很成功,因为我看到了NSLog和产品标题。
但在此之后,我总是在购买过程中获得transaction failed!
-(void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions
{
for (SKPaymentTransaction *transaction in transactions)
{
switch (transaction.transactionState) {
case SKPaymentTransactionStatePurchased:
// [self unlockFeature];
NSLog(@"Transaction purchased");
[[SKPaymentQueue defaultQueue] finishTransaction:transaction];
if (_product.downloadable) {
[[SKPaymentQueue defaultQueue] startDownloads:transaction.downloads];
}
break;
case SKPaymentTransactionStateRestored:
if (transaction.downloads) {
[[SKPaymentQueue defaultQueue] startDownloads:transaction.downloads];
NSLog(@"Transaction downloading now...");
} else {
// unlock features
[[SKPaymentQueue defaultQueue] finishTransaction:transaction];
NSLog(@"Transaction finish");
}
break;
case SKPaymentTransactionStateFailed:
NSLog(@"Transaction Failed");
[[SKPaymentQueue defaultQueue]
finishTransaction:transaction];
break;
default:
break;
}
}
}
什么似乎有问题,我该如何调试这部分?有没有办法让我清除以前的交易测试或检查是否有任何待处理的交易干扰了当前的测试?我仍然在沙盒模式下测试它。错误是以一种非常直接的方式抛出的,这给我的印象是它没有真正通过Apple服务器并且事务错误发生在本地,某种先前的事务测试冲突或者我仍然没有找到的东西。
还有一点需要提及的是,我正在购买非消耗品,如果交易成功,它将触发下载(我希望。)。