无法解雇PKPaymentAuthorizationViewController

时间:2015-11-24 22:42:18

标签: ios objective-c applepay

我正在为我的应用程序实施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中的取消按钮,它也不会消失。

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

@interface ApplePayManager : UIViewController<PKPaymentAuthorizationViewControllerDelegate, UIAlertViewDelegate>

关于我做错的任何想法?为什么视图控制器没有消失?

最后,我对iOS有点新鲜。因此,我非常感谢指南和/或链接,以澄清我的疑虑!

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

1 个答案:

答案 0 :(得分:1)

这很有用。我的队友发现了这个解决方案。事实证明,我们提供ApplePay View的ViewController不是rootVC。因此,将其切换到rootVC是有效的。

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

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