PKPaymentAuthorizationViewController is crashing unexpectedly on iOS 8.4

╄→гoц情女王★ 提交于 2019-12-11 19:36:45

问题


Background: I used same code for iOS 8.2,8.3 it was working fine.

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

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

PaymentRequest Code:

        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;

Question: Now on iOS 8.4 when I try to present my paymentPane its value is nil somehow.

Fatal Exception: NSInvalidArgumentException Application tried to present a nil modal view controller on target .

What I have already tried by googling and using answers from stackoverflow.

  • Used Checks like

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

    and

    [PKPaymentAuthorizationViewController canMakePayments]

  • Checking my merchant id is valid or not.

  • Checking All the code I used for request is valid or not.

回答1:


  1. Check whether you've added Credit card information in your device Passbook or not.

  2. Check whether you can make payment using your device.

    Objective C :

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

  3. Check whether you can make payment using the allowed payment networks.

    Objective 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");
    }
    Swift :
    let paymentNetworks = [PKPaymentNetworkAmex, PKPaymentNetworkMasterCard, PKPaymentNetworkVisa]
    if PKPaymentAuthorizationViewController.canMakePaymentsUsingNetworks(paymentNetworks) {
        NSLog(@"Can Make payment with your card");
    }
    else {
        NSLog(@"Card is not supporting");
    }



回答2:


I have also had similar problems when running inside the Xcode debugger. As a workaround I stop the app in Xcode and then manually start the app on the iPhone or iPad.

One drawback with this is obviously that you can't debug any issues. I've had to resort to NSLog and reading the console log.



来源:https://stackoverflow.com/questions/31760725/pkpaymentauthorizationviewcontroller-is-crashing-unexpectedly-on-ios-8-4

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!