问题
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:
Check whether you've added
Credit card
information in your devicePassbook
or not.Check whether you can make payment using your device.
Objective C :
Swift :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"); }
- Check whether you can make payment using the allowed
payment networks
.
Objective C :
Swift :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"); }
回答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