Samraan Khaan
Samraan Khaan

Reputation: 480

PKPaymentAuthorizationViewController is crashing unexpectedly on iOS 8.4

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.

Upvotes: 0

Views: 1612

Answers (2)

arthankamal
arthankamal

Reputation: 6413

  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");
    }

Upvotes: 2

Jon Tirsen
Jon Tirsen

Reputation: 4990

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.

Upvotes: 0

Related Questions