Apple Pay 在将 Xcode 更新到版本 10.4 后无法正常工作



Apple Pay在模拟器中运行良好,但在将Xcode升级到10.4后,它停止工作。

  1. Apple Pay 弹出窗口出现。
  2. 单击使用密码付款后,它会隐藏而不验证付款。

  3. 不调用方法- (void)paymentAuthorizationViewController:(PKPaymentAuthorizationViewController *)controller didAuthorizePayment:(PKPayment *)payment completion:(void (^)(PKPaymentAuthorizationStatus))completion {}

法典:

NSString *merchantIdentifier = [STPPaymentConfiguration sharedConfiguration].appleMerchantIdentifier;
PKPaymentRequest *paymentRequest = [Stripe paymentRequestWithMerchantIdentifier:merchantIdentifier country:@"US" currency:currencyCode];
paymentRequest.paymentSummaryItems = @[
[PKPaymentSummaryItem summaryItemWithLabel:@"Fancy Hat" amount:[NSDecimalNumber decimalNumberWithString:amount]],
// The final line should represent your company;
// it'll be prepended with the word "Pay" (i.e. "Pay iHats, Inc $50")
[PKPaymentSummaryItem summaryItemWithLabel:@"iHats, Inc" amount:[NSDecimalNumber decimalNumberWithString:amount]],
];
if ([Stripe canSubmitPaymentRequest:paymentRequest]) {
// Setup payment authorization view controller
PKPaymentAuthorizationViewController *paymentAuthorizationViewController = [[PKPaymentAuthorizationViewController alloc] initWithPaymentRequest:paymentRequest];
paymentAuthorizationViewController.delegate = self;
// Present payment authorization view controller
FlutterViewController* controller = (FlutterViewController* )[[UIApplication sharedApplication].keyWindow rootViewController];
[controller presentViewController:paymentAuthorizationViewController animated:YES completion:nil];
}

他们确实更改了签名,因此有一种新的方法来调用iOS11+,而iOS9和iOS10仍然需要旧方法:

/// for iOS 9 and iOS 10
func paymentAuthorizationViewController(_ controller: PKPaymentAuthorizationViewController,
didAuthorizePayment payment: PKPayment,
completion: @escaping (PKPaymentAuthorizationStatus) -> Void) {
...
}
@available(iOS 11.0, *)
func paymentAuthorizationViewController(_ controller: PKPaymentAuthorizationViewController,
didAuthorizePayment payment: PKPayment,
handler: @escaping (PKPaymentAuthorizationResult) -> Void) {
...
}

它似乎在 12.4 模拟器中不起作用。您需要在真实设备上进行测试。具有先前iOS的模拟器似乎可以工作(iOS10对我有用(。模拟器问题在这个问题中讨论:ApplePay 'paymentAuthorizationViewController:didAuthorizePayment:handler:' 在 Xcode Simulator 10.3 中未调用

最新更新