本文介绍了Apple付费PKPaymentauthorizationViewController在加载付款请求时始终返回nil的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am getting the PK Payment auth view controller instance returned as nil. What is wrong with this code?

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,您将获得 nil PKPaymentAuthorizationViewController 的值。你甚至可以在控制台上找到一个例外,说明此设备无法付款。

Before accessing the PKPaymentAuthorizationViewController, you should configure Apple Pay properly on your iPhone device. If you have not configured Apple Pay on your device you'll get nil value for PKPaymentAuthorizationViewController. You can even find an exception on the console stating "This device cannot make payment."

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

To configure Apple Pay on your device follow the below steps:


  • 转到设置

  • 选择 Passbook和Apple Pay 选项(如果在设置中看不到此选项,请转到常规 - >语言和区域,将您所在的地区更改为美国或英国,在此之后,您将能够在设置中看到 Passbook& Apple Pay 选项。

  • 打开 Passbook 来自主屏幕的应用程序并配置有效的信用卡/借记卡(仅限美国/英国的卡)。

  • 验证添加的卡后,运行您的应用程序您将获得有效 PKPaymentAuthorizationViewController 实例。

  • Go to Settings.
  • Select Passbook and Apple Pay option (if this option is not visible in settings, go to General -> Language & Region, change your region to US or UK, after this you'll be able to see the Passbook & Apple Pay option in Settings)
  • Open Passbook application from your home screen and configure a valid credit/debit card (US/UK based card only).
  • After verifying the added card, run your application you'll get a valid PKPaymentAuthorizationViewController instance.

希望这会有所帮助。

这篇关于Apple付费PKPaymentauthorizationViewController在加载付款请求时始终返回nil的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 02:42