我正在为我的应用程序实施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
最佳答案 这很有效.我的队友发现了这个解决方案.事实证明,我们提供ApplePay View的ViewController不是rootVC.因此,将其切换到rootVC是有效的.
UIViewController *rootViewController = [[[UIApplication sharedApplication] keyWindow] rootViewController];
[rootViewController presentViewController:paymentPane animated:TRUE completion:nil];