无法关闭 PKPaymentAuthorizationViewController

Unable to dismiss PKPaymentAuthorizationViewController

我正在为我的应用程序实施 Apple Pay。虽然我几乎已经弄清楚了所有事情,但我无法取消进行身份验证的 PKPaymentAuthorizationViewController。 这是我的代码..

-(void) viewDidAppear:(BOOL)animated {
    // request is initialized here.
    paymentPane = [[PKPaymentAuthorizationViewController alloc] initWithPaymentRequest:request];

    //paymentPane is not nil. 
    paymentPane.delegate = self;

    [self presentViewController:paymentPane animated:TRUE completion:nil];
}

调用上述函数并成功呈现 Apple Pay View Controller 以验证支付。我已经从委托中实现了以下方法,如下所示:

-(void)paymentAuthorizationViewControllerDidFinish:(PKPaymentAuthorizationViewController *)controller {
    [self dismissViewControllerAnimated:YES completion:nil];
}

- (void)paymentAuthorizationViewController:(PKPaymentAuthorizationViewController *)controller didAuthorizePayment:(PKPayment *)payment completion:(void (^)(PKPaymentAuthorizationStatus))completion {
     NSLog(@"%@", [payment.token description]);
     completion(PKPaymentAuthorizationStatusSuccess);
}

理想情况下,它首先点击 didAuthorizePayment,在那里我们验证支付,如果成功则传递成功,然后调用 paymentAuthorizationViewControllerDidFinish 并用于完成交易并隐藏 Apple View Controller。我在那里设置了断点,它同时触发了两个函数,但 ViewController 并没有消失。即使您点击 Apple Pay View 中的“取消”按钮,它也不会运行。

我的 class 声明如下,并确实实现了所需的委托。

@interface ApplePayManager : UIViewController<PKPaymentAuthorizationViewControllerDelegate, UIAlertViewDelegate>

对我做错了什么有什么想法吗?为什么视图控制器不解散?

最后,我对iOS有点陌生。所以我很感激指南 and/or 链接来澄清我的疑虑!

已查看: http://www.raywenderlich.com/87300/apple-pay-tutorial https://dzone.com/articles/integrating-your-ios-app-apple

这成功了。我的队友发现了这个解决方案。事实证明,我们展示 ApplePay 视图的 ViewController 不是 rootVC。因此,将它切换到 rootVC 是可行的。

  UIViewController *rootViewController = [[[UIApplication sharedApplication] keyWindow] rootViewController];

  [rootViewController presentViewController:paymentPane animated:TRUE completion:nil];