Apple付费PKPaymentauthorizationViewController在加载付款请求时始终返回nil

我将PK Payment auth视图控制器实例返回为nil。 这段代码有什么问题?

if([PKPaymentAuthorizationViewController canMakePayments]) { if ([PKPaymentAuthorizationViewController canMakePaymentsUsingNetworks:@[PKPaymentNetworkAmex, PKPaymentNetworkMasterCard, PKPaymentNetworkVisa]]) { PKPaymentRequest *request = [[PKPaymentRequest alloc] init]; request.currencyCode = @"USD"; request.countryCode = @"US"; request.merchantCapabilities = 0; request.requiredBillingAddressFields=PKAddressFieldAll; request.merchantIdentifier = @"merchant.com.domain.mine"; PKPaymentSummaryItem *item = [[PKPaymentSummaryItem alloc] init]; item.label=@"Merchant"; item.amount=[NSDecimalNumber decimalNumberWithString:@"10"]; request.paymentSummaryItems=@[item]; PKPaymentAuthorizationViewController *viewController = [[PKPaymentAuthorizationViewController alloc] initWithPaymentRequest:request]; viewController.delegate = self; [self presentViewController:viewController animated:YES completion:nil]; } } 

在访问PKPaymentAuthorizationViewController之前,您应该在iPhone设备上正确配置Apple Pay。 如果您尚未在设备上配置Apple Pay,则PKPaymentAuthorizationViewController将获得nil值。 您甚至可以在控制台上找到“ This device cannot make payment. ”的例外情况This device cannot make payment.

要在您的设备上配置Apple Pay,请按以下步骤操作:

  • 转到“设置”
  • 选择Passbook和Apple Pay选项(如果在设置中看不到此选项,请转到常规 – >语言和地区 ,将您的地区更改为美国或英国,之后您将能够在设置中看到Passbook和Apple Pay选项)
  • 从主屏幕打开Passbook应用程序并配置有效的信用卡/借记卡(仅限美国/英国的卡)。
  • validation添加的卡后,运行您的应用程序,您将获得一个有效的PKPaymentAuthorizationViewController实例。

希望这会有所帮助。