PKPaymentAuthorizationViewController在iOS 8.4上意外崩溃

时间:2015-08-01 10:15:23

标签: ios objective-c ios8 applepay

后台:我在iOS 8.2,8.3上使用了相同的代码,但它运行正常。

PKPaymentAuthorizationViewController *paymentPane = [[PKPaymentAuthorizationViewController alloc] initWithPaymentRequest:request];
paymentPane.delegate = self;

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

PaymentRequest代码:

        PKPaymentRequest *request = [[PKPaymentRequest alloc] init];


        NSString *chargeApplePay=[NSString stringWithFormat:@"%.02f",pay];

        PKPaymentSummaryItem *total = [PKPaymentSummaryItem summaryItemWithLabel:@"Grand Total"
                                                                          amount:[NSDecimalNumber decimalNumberWithString:chargeApplePay]];

        request.paymentSummaryItems = @[total];
        request.countryCode = @"US";
        request.currencyCode = @"USD";
        request.supportedNetworks = @[PKPaymentNetworkAmex, PKPaymentNetworkMasterCard, PKPaymentNetworkVisa];
        request.merchantIdentifier = @"valid.com.myIdentifier";
        request.merchantCapabilities = PKMerchantCapability3DS;

问题:现在在iOS 8.4上,当我尝试提供我的paymentPane时,其价值是以某种方式为零。

  

致命异常:NSInvalidArgumentException应用程序尝试过   在目标上显示一个零模态视图控制器。

我已经尝试使用Google搜索并使用stackoverflow中的答案。

  • 二手检查

    [PKPaymentAuthorizationViewController    canMakePaymentsUsingNetworks:@[PKPaymentNetworkAmex, PKPaymentNetworkMasterCard, PKPaymentNetworkVisa]] 
    

    [PKPaymentAuthorizationViewController canMakePayments]

  • 检查我的商家ID是否有效。

  • 检查我用于请求的所有代码是否有效。

2 个答案:

答案 0 :(得分:2)

  1. 检查您是否在设备Credit card中添加了Passbook信息。

  2. 检查您是否可以使用自己的设备付款。

    目标C:

    if ([PKPaymentAuthorizationViewController canMakePayments]) {
        NSLog(@"Can Make Payments");
    }
    else {
        NSLog(@"Can't Make payments");
    }
    
    斯威夫特:
    if PKPaymentAuthorizationViewController.canMakePayments() {
        NSLog(@"Can Make Payments");
    }
    else {
        NSLog(@"Can't Make Payments");
    }
    

  3. 检查您是否可以使用允许的payment networks付款。

    目标C:
    NSArray *paymentNetworks = [NSArray arrayWithObjects:PKPaymentNetworkMasterCard, PKPaymentNetworkVisa, PKPaymentNetworkAmex, nil];
    if ([PKPaymentAuthorizationViewController canMakePaymentsUsingNetworks:paymentNetworks]) {
        NSLog(@"Can Make payment with your card");
    }
    else {
        NSLog(@"Card is not supporting");
    }
    斯威夫特:
    let paymentNetworks = [PKPaymentNetworkAmex, PKPaymentNetworkMasterCard, PKPaymentNetworkVisa]
    if PKPaymentAuthorizationViewController.canMakePaymentsUsingNetworks(paymentNetworks) {
        NSLog(@"Can Make payment with your card");
    }
    else {
        NSLog(@"Card is not supporting");
    }

答案 1 :(得分:0)

在Xcode调试器中运行时,我也有类似的问题。作为解决方法,我在Xcode中停止应用程序,然后在iPhone或iPad上手动启动应用程序。

显然,您无法调试任何问题。我不得不求助于NSLog并阅读控制台日志。