我有两个问题:
SKPaymentTransactionObserver
paymentQueue:updatedTransactions:
中,我收到SKPaymentTransactionStateFailed
状态"Cannot connect to iTunes Store"
错误。paymentQueue:updatedTransactions:
也会被调出失败状态注意:我在使用网络链接调节器的模拟器上进行测试(HighLatencyDNS自定义配置文件500毫秒)
此外,我在DNS延迟超过0.5秒的网络中也注意到了这个问题
将付款添加到队列:
- (BOOL)internalBeginPurchaseFor:(NSString *)productId
{
if ([SKPaymentQueue canMakePayments]) {
SKProduct *product;
if ((product = self.products[productId])) {
SKPayment *payment = [SKPayment paymentWithProduct:product];
[[SKPaymentQueue defaultQueue] addTransactionObserver:self];
[[SKPaymentQueue defaultQueue] addPayment:payment];
return YES;
}
}
return NO;
}
处理交易状态:
- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray<SKPaymentTransaction *> *)transactions
{
for (SKPaymentTransaction *transaction in transactions)
{
NSString *transactionIdentifier = transaction.transactionIdentifier;
NSString *transactionDetails = @"";
switch (transaction.transactionState) {
case SKPaymentTransactionStatePurchasing:
NSLog(@"User is purchasing");
transactionDetails = @"User purchasing";
break;
case SKPaymentTransactionStatePurchased:
NSLog(@"User purchased");
[[SKPaymentQueue defaultQueue] finishTransaction:transaction];
[self executeHandlerForTransaction:transaction andSuccessFlag:YES];
transactionDetails = @"User purchased";
break;
case SKPaymentTransactionStateFailed:
NSLog(@"failed to purchase");
[[SKPaymentQueue defaultQueue] finishTransaction:transaction];
[self executeHandlerForTransaction:transaction andSuccessFlag:NO];
transactionDetails = @"Failed to purchase";
break;
case SKPaymentTransactionStateRestored:
NSLog(@"restored transaction");
transactionDetails = @"Restored transaction";
break;
case SKPaymentTransactionStateDeferred:
NSLog(@"pending for transaction");
transactionDetails = @"Pending for transaction";
break;
}
NSString *stringData = [NSString stringWithFormat:@"%@ for transaction Identifier %@",transactionDetails, transactionIdentifier];
[EventLogger logEventOfType:PURCHASE_PLAN withData:stringData andNotes:@"APIAPurchase"];
}
}
有什么建议吗?