I am trying to implement Apple Pay for my app. I have the PKPaymentAuthorizationViewController trying to load up the Apple Pay View. This view controller was being returned as Nil by the constructor if I didn't have any cards already in my wallet. So, I decided to guide the user though the process where they enter their card information. I was able to achieve this using
PKPassLibrary* lib = [[PKPassLibrary alloc] init];
[lib openPaymentSetup];
Here is the part where I have the initialization of the PKPaymentAuthorizationViewController. This returns a valid object on Simulator showing the view. But on a real device without a configured credit card returns nil and runs into an runtime exception. Here is the initialization code:
if ([PKPaymentAuthorizationViewController canMakePayments]) {
// init arr
[arr addObject:total];
request.paymentSummaryItems = arr;
PKPaymentAuthorizationViewController *paymentPane = [[PKPaymentAuthorizationViewController alloc] initWithPaymentRequest:request];
paymentPane.delegate = self;
[self presentViewController:paymentPane animated:TRUE completion:nil];
}
Here the array is a valid NSArray of PKPaymentSummaryItem which is why is successfully works on simulator.
I need to call the above method of openPaymentSetup, everytime I see a user without the credit card in their wallet. Is there a way to detect that?
Currently I am using
if ( [PKPassLibrary isPassLibraryAvailable] ) {
PKPassLibrary* lib = [[PKPassLibrary alloc] init];
if ([lib passesOfType:PKPassTypePayment].count == 0 ) {
[lib openPaymentSetup];
}
}
But this will not work since I am looking at the count of passes in wallet. Which may be like boarding pass for airline, or eventbrite pass, etc.
Looked at : PKPaymentAuthorizationViewController present as nil view controller
Apple pay PKPaymentauthorizationViewController always returning nil when loaded with Payment request
canMakePaymentsUsingNetworks:
method, not thecanMakePayments
method. – rmaddy