I tried to implement Apple Pay in my app, but I am getting a error such that " Application tried to present a nil modal view controller on target " in the following snippet, can any one tell were I am went wrong.
PKPaymentAuthorizationViewController *vc = [[PKPaymentAuthorizationViewController alloc] initWithPaymentRequest:payment];
vc.delegate = self;
[self presentViewController:vc animated:YES completion:nil];
Actually it will work on Simulator, but not on real device when Apple Pay IS NOT SUPORTED in the country the device is assigned to. Please consider this.
// once check your controller is it initializing properly or not
if (!viewController) {
[self presentViewController:vc animated:YES completion:nil];
} else {
// handle error , may be request is not proper to initializing the PKPaymentAuthorizationViewController
}
It's likely that your app's Apple Pay entitlement is not set up correctly.
I've noticed canMakePayments
returns YES
and canMakePaymentsUsingNetworks:
returns NO
when the entitlement is not set.
(I've also noticed that they can both return YES
when the merchant ID you set on your PKPaymentRequest
does not match the merchant ID of your Apple Pay entitlement. In this case, your PKPaymentAuthorizationViewController
will be non-nil, but presenting it logs a cryptic error in the console).
So to verify that Apple Pay is configured for your app, ensure that "Apple Pay" is "On" in the Capabilities section of your target settings, and that it has a merchant identifier (which you'll need to set up if you haven't already).
Then either:
PassKit
integration method, ensure that you are setting merchantIdentifier
property to the matching merchant identifier in the entitlement.Please check this code:
if ([PKPaymentAuthorizationViewController canMakePayments]) {
NSLog(@"Can Make Payments");
PKPaymentAuthorizationViewController *viewController = [[PKPaymentAuthorizationViewController alloc] initWithPaymentRequest:request];
if (!viewController) { /* ... Handle error ... */ }
viewController.delegate = self;
[self presentViewController:viewController animated:YES completion:nil];
}
else {
NSLog(@"Can't Make payments");
}
or
refer this url with sample code: https://developer.apple.com/library/content/ApplePay_Guide/CreateRequest.html#//apple_ref/doc/uid/TP40014764-CH3-SW2
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With