我将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];
}
}
答案 0 :(得分:6)
在访问PKPaymentAuthorizationViewController
之前,您应该在iPhone设备上正确配置Apple Pay。如果您尚未在设备上配置Apple Pay,则nil
的值为PKPaymentAuthorizationViewController
。您甚至可以在控制台上找到一个说明“This device cannot make payment.
”
要在您的设备上配置Apple Pay,请按照以下步骤操作:
PKPaymentAuthorizationViewController
实例。希望这会有所帮助。
答案 1 :(得分:0)
我有一个类似的问题。似乎您已包含它,但是对于其他为此苦苦挣扎的人来说,我的问题并不是最初向请求提供vendorCapabilities。
迅速:
request.merchantCapabilities = PKMerchantCapability.capability3DS
https://developer.apple.com/documentation/passkit/pkmerchantcapability?language=objc
答案 2 :(得分:0)
如果要使用原始值实例化支持网络,请确保使用正确的大写字母来完成它们。
// Summarized for posting purposes
let networks = ["AmEx", "Visa", "MasterCard", "Discover"].reduce(into: [PKPaymentNetwork]()) { $0.append(PKPaymentNetwork($1)) }
if PKPaymentAuthorizationViewController.canMakePayments(usingNetworks: networks, capabilities: .capability3DS) {
// Hooray
}